﻿Imports System
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
<Serializable()> Public Class MetGeneral

    Implements ICloneable

    'Private m_ArrFileCommunication As New FileCommunication
    Private m_DataChanged As Boolean = False '气象数据是否发生变化的标志
    Private m_ArrayMetData(-1) As StructureGeneralMet '常规气象数组，用于储存常规气象数据
    Private m_FileName As String '文件名称，含路径。
    Private DataType As Integer = 0 '有两种数据记录格式，一种是从0-23点，另1种是从1-24点。当为第2种时，时间上应-1
    Private m_Location As New Location '位置
    Private m_InsetSchedule As Double  '插值进度
    Private m_SaveSchedule As Double  '保存进度
    Private m_IsInsert As Boolean = True '导出数据时进行插值
    Private m_type As Boolean = True
    <NonSerialized()> Public IsCalpuff As Boolean = False   'calpuff
    <NonSerialized()> Public IsPricipitation As Boolean = False  '降水

    Property Type() As Boolean
        Get
            Return Me.m_type
        End Get
        Set(ByVal value As Boolean)
            Me.m_type = value
        End Set
    End Property
    ''' <summary>
    ''' 气象数据是否发生变化的标志
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property DataChanged() As Boolean
        Get
            Return m_DataChanged
        End Get
        Set(ByVal value As Boolean)
            m_DataChanged = value
        End Set
    End Property
   
    ''' <summary>
    ''' 常规气象数组，用于储存常规气象数据
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property ArrayMetData() As StructureGeneralMet()
        Get
            Return Me.m_ArrayMetData
        End Get
        Set(ByVal value As StructureGeneralMet())
            Me.m_ArrayMetData = value
        End Set
    End Property
    ''' <summary>
    ''' 地面气象数据的文件名称，含路径
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property FileName() As String
        Get
            Return Me.m_FileName
        End Get
        Set(ByVal value As String)
            Me.m_FileName = value
        End Set
    End Property
    ''' <summary>
    ''' 地理位置等参数
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property Location() As Location

        Get
            Return Me.m_Location
        End Get
        Set(ByVal value As Location)
            Me.m_Location = value
        End Set
    End Property
    ''' <summary>
    ''' 插值进度
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property InsetSchedule() As Double
        Get
            Return m_InsetSchedule
        End Get
        Set(ByVal value As Double)
            m_InsetSchedule = value
        End Set
    End Property
    ''' <summary>
    ''' 保存进度
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property SaveSchedule() As Double
        Get
            Return m_SaveSchedule
        End Get
        Set(ByVal value As Double)
            m_SaveSchedule = value
        End Set
    End Property
    ''' <summary>
    ''' 导出数据时进行插值
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property IsInsert() As Boolean
        Get
            Return Me.m_IsInsert
        End Get
        Set(ByVal value As Boolean)
            Me.m_IsInsert = value
        End Set
    End Property

    ''' <summary>
    ''' 获得常规气象数据的开始日期
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetStartDate() As DateTime '获得常规气象数据的开始日期
        If Me.m_ArrayMetData IsNot Nothing AndAlso Me.m_ArrayMetData.Length > 0 Then
            Return Me.m_ArrayMetData(0).m_DateTime
        Else
            Return New DateTime(2008, 1, 1, 0, 0, 0)
        End If
    End Function

    ''' <summary>
    ''' 获得常规气象数据的开始日期
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetEndDate() As DateTime '获得常规气象数据的开始日期
        If Me.m_ArrayMetData IsNot Nothing AndAlso Me.m_ArrayMetData.Length > 0 Then
            Return Me.m_ArrayMetData(Me.m_ArrayMetData.Length - 1).m_DateTime
        Else
            Return New DateTime(2007, 12, 31, 23, 0, 0)
        End If
    End Function

    ''' <summary>
    ''' 初始化时间数组
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()
        'ResetArrayMetData(New DateTime(2007, 1, 1, 1, 0, 0), New DateTime(2007, 1, 1, 0, 0, 0))
    End Sub

    ''' <summary>
    ''' 设置气象数组
    ''' </summary>
    ''' <param name="ArrayMetData"></param>
    ''' <remarks></remarks>
    Public Sub SetArrayMetData(ByVal ArrayMetData() As StructureGeneralMet)
        If ArrayMetData IsNot Nothing And m_ArrayMetData IsNot Nothing Then '如果数组不为空则开始运行
            If ArrayMetData(0).m_DateTime < m_ArrayMetData(0).m_DateTime Then
                '插入的数组的下限小于原数组，但上限不大于原数组
                MessageBox.Show("数组超出设定值的下限!", "错误")

            ElseIf ArrayMetData(ArrayMetData.Length - 1).m_DateTime > m_ArrayMetData(m_ArrayMetData.Length - 1).m_DateTime Then
                MessageBox.Show("数组超出设定值的上限!", "错误")
            Else
                Dim InterHours As Integer
                InterHours = (ArrayMetData(0).m_DateTime - m_ArrayMetData(0).m_DateTime).TotalHours  '中间间隔的小时数
                Dim i As Integer
                For i = 0 To ArrayMetData.Length - 1
                    m_ArrayMetData(i + InterHours) = ArrayMetData(i)
                Next
            End If
        End If
    End Sub

    ''' <summary>
    ''' 获取给定时间范围内的数组的气象数据
    ''' </summary>
    ''' <param name="sdate"></param>
    ''' <param name="edate"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetArrayMetData(ByVal sdate As DateTime, ByVal edate As DateTime) As StructureGeneralMet()
        If m_ArrayMetData IsNot Nothing Then '如果数组不为空则开始运行
            Dim ArrayMetData((sdate - edate).TotalHours) As StructureGeneralMet
            If sdate < m_ArrayMetData(0).m_DateTime Then
                MessageBox.Show("数组超出设定值的下限!", "错误")
                Return Nothing
            ElseIf edate < m_ArrayMetData(m_ArrayMetData.Length - 1).m_DateTime Then
                MessageBox.Show("数组超出设定值的上限!", "错误")
                Return Nothing
            Else
                Dim InterHours As Integer
                InterHours = (sdate - m_ArrayMetData(0).m_DateTime).TotalHours  '中间间隔的小时数
                Dim i As Integer
                For i = 0 To (sdate - edate).TotalHours
                    ArrayMetData(i) = m_ArrayMetData(i + InterHours)
                Next
                Return ArrayMetData
            End If
        Else
            Return Nothing
        End If
    End Function

    ''' <summary>
    ''' 根据给定的时间范围，重新设置数组
    ''' </summary>
    ''' <param name="sdate"></param>
    ''' <param name="edate"></param>
    ''' <remarks></remarks>
    Public Sub ResetArrayMetData(ByVal sdate As DateTime, ByVal edate As DateTime)
        Dim A(0 To (edate - sdate).TotalHours) As StructureGeneralMet '设置一个空数组
        Dim i As Integer
        For i = 0 To A.Length - 1
            A(i) = New StructureGeneralMet
            A(i).m_DateTime = sdate.AddHours(i)
        Next
        If m_ArrayMetData.Length = 0 Then '如果原数组为空，则
            Me.m_ArrayMetData = A
        Else
            If sdate >= m_ArrayMetData(0).m_DateTime And edate <= m_ArrayMetData(m_ArrayMetData.Length - 1).m_DateTime Then
                '如果新数组在原数组的内部，则截断原数组
                For i = 0 To A.Length - 1
                    A(i) = m_ArrayMetData(i + (sdate - m_ArrayMetData(0).m_DateTime).TotalHours)
                Next
            ElseIf sdate < m_ArrayMetData(0).m_DateTime And edate <= m_ArrayMetData(m_ArrayMetData.Length - 1).m_DateTime Then
                '如果下限超出，但上限未超出
                For i = (m_ArrayMetData(0).m_DateTime - sdate).TotalHours To A.Length - 1
                    A(i) = m_ArrayMetData(i - (m_ArrayMetData(0).m_DateTime - sdate).TotalHours)
                Next
            ElseIf sdate >= m_ArrayMetData(0).m_DateTime And edate > m_ArrayMetData(m_ArrayMetData.Length - 1).m_DateTime Then
                '如果下限未超出，但上限超出
                For i = 0 To (m_ArrayMetData(m_ArrayMetData.Length - 1).m_DateTime - sdate).TotalHours
                    A(i) = m_ArrayMetData(i + (sdate - m_ArrayMetData(0).m_DateTime).TotalHours)
                Next
            ElseIf sdate < m_ArrayMetData(0).m_DateTime And edate > m_ArrayMetData(m_ArrayMetData.Length - 1).m_DateTime Then
                '上、下限均超出
                For i = 0 To m_ArrayMetData.Length - 1
                    A(i + (m_ArrayMetData(0).m_DateTime - sdate).TotalHours) = m_ArrayMetData(i)
                Next
            End If
        End If
        Me.m_ArrayMetData = A
    End Sub

    ''' <summary>
    ''' 设置某一常规气象数据到数组中
    ''' </summary>
    ''' <param name="MetData">给定的常规气象数据</param>
    ''' <remarks></remarks>
    Public Sub SetMetData(ByVal MetData As StructureGeneralMet)
        If m_ArrayMetData IsNot Nothing And m_ArrayMetData.Length > 0 Then '如果数组不为空则开始运行
            If MetData.m_DateTime < m_ArrayMetData(0).m_DateTime Or MetData.m_DateTime > m_ArrayMetData(m_ArrayMetData.Length - 1).m_DateTime Then
                MessageBox.Show("输入的时间数据超出的界限")
            Else
                Dim IDate As Integer
                IDate = (MetData.m_DateTime - m_ArrayMetData(0).m_DateTime).TotalHours
                m_ArrayMetData(IDate) = MetData
            End If
        End If
    End Sub
    ''' <summary>
    ''' 在现在的数据中加入新的数据
    ''' </summary>
    ''' <param name="AMetData"></param>
    ''' <remarks></remarks>
    Public Sub AddMetData(ByVal AMetData As MetGeneral)
        If Me.m_ArrayMetData.Length <= 24 Then '如果为空，则直接给值
            Me.m_ArrayMetData = AMetData.ArrayMetData
            Me.m_FileName = AMetData.FileName  '文件名称，含路径。
            Me.m_Location = AMetData.Location  '位置
        Else
            Dim startdate As New Date
            If Me.GetStartDate <= AMetData.GetStartDate Then
                startdate = Me.GetStartDate
            Else
                startdate = AMetData.GetStartDate
            End If
            Dim enddate As New Date
            If Me.GetEndDate >= AMetData.GetEndDate Then
                enddate = Me.GetEndDate
            Else
                enddate = AMetData.GetEndDate
            End If
            Me.ResetArrayMetData(startdate, enddate)
            For i As Integer = 0 To (AMetData.GetEndDate - AMetData.GetStartDate).TotalHours + 1 - 1
                Me.SetMetData(AMetData.ArrayMetData(i))
            Next
        End If

    End Sub

    ''' <summary>
    ''' 获取指定时间的常规地面气象数据
    ''' </summary>
    ''' <param name="mdate">给定的时间</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overloads Function GetMetData(ByVal mdate As DateTime) As StructureGeneralMet
        Dim index As Integer = (mdate - Me.GetStartDate).TotalHours
        Return Me.m_ArrayMetData(index)
    End Function

    ''' <summary>
    ''' 获取指定序号的地面气象数据
    ''' </summary>
    ''' <param name="nIndex">给定的数组序号，从0开始</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overloads Function GetMetData(ByVal nIndex As Integer) As StructureGeneralMet
        If nIndex >= 0 And nIndex <= Me.m_ArrayMetData.Length - 1 Then
            Return Me.m_ArrayMetData(nIndex)
        Else
            Return Nothing
        End If
    End Function



    ''' <summary>
    ''' 打开数据文件
    ''' </summary>
    ''' <remarks></remarks>
    Public Function OpenMetDataFileOQA() As Boolean
        Dim LoadDlg As New OpenFileDialog
        LoadDlg.Filter = "AERMET 地面气象数据文件(*.OQA)|*.OQA"
        If LoadDlg.ShowDialog() = DialogResult.OK Then
            '显示打开对话框
            If LoadDlg.FileName.Substring(LoadDlg.FileName.Length - 3, 3).ToUpper = "OQA" Then
                LoadMetData(LoadDlg.FileName)
                Me.m_FileName = LoadDlg.FileName
                Return True
                Me.m_FileName = ""
                Return False
            End If
        Else
            Return False
        End If
    End Function
    ''' <summary>
    ''' 打开数据文件
    ''' </summary>
    ''' <remarks></remarks>
    Public Function OpenMetDataFile() As Boolean
        Dim LoadDlg As New OpenFileDialog
        '..............................
        '小李改
        If Me.IsCalpuff = False Then

            LoadDlg.Filter = "AERMET 地面气象数据文件(*.OQA)|*.OQA|A文件 地面气象观测数据文件(*.txt)|*.txt|地面气象观测数据文件(*.144)|*.144|HUSWO数据格式(*.All)|*.All"
        Else
            LoadDlg.Filter = "AERMET 地面气象数据文件(*.OQA)|*.OQA|A文件 地面气象观测数据文件(*.txt)|*.txt|地面气象观测数据文件(*.144)|*.144|HUSWO数据格式(*.All)|*.All|TD3240数据格式(*.TD3240)|*.TD3240"
        End If
        '..............................

        'LoadDlg.Filter = "AERMET 地面气象数据文件(*.OQA)|*.OQA|A文件 地面气象观测数据文件(*.txt)|*.txt|地面气象观测数据文件(*.144)|*.144|HUSWO数据格式(*.All)|*.All"
        LoadDlg.Multiselect = True
        LoadDlg.FilterIndex = 2
        '显示打开对话框
        If LoadDlg.ShowDialog() = DialogResult.OK Then
            '初始化数组
            ReDim Me.m_ArrayMetData(-1)
            Me.m_DataChanged = False
            Me.m_FileName = ""
            Me.m_InsetSchedule = 0
            Me.m_Location = New Location
            Me.m_SaveSchedule = 0
            '导入数据
            If LoadDlg.FileName.Substring(LoadDlg.FileName.Length - 3, 3).ToUpper = "OQA" Then
                Me.ShowAll = False '是否显示ALL标志
                Me.ShowTd3240 = False '是否显示TD3240标志
                LoadMetData(LoadDlg.FileName)
                Me.m_FileName = LoadDlg.FileName
                Me.m_type = True '是否显示144标志
                Return True
            ElseIf LoadDlg.FileName.Substring(LoadDlg.FileName.Length - 3, 3).ToUpper = "TXT" Then
                Me.ShowAll = False
                Me.ShowTd3240 = False
                Dim Afile As String
                For Each Afile In LoadDlg.FileNames

                    Dim AMetGeneral As New MetGeneral
                    AMetGeneral = LoadSingleAFile(Afile)
                    Me.AddMetData(AMetGeneral)
                Next
                Me.m_FileName = LoadDlg.FileName
                Me.m_type = True
                Return True
            ElseIf LoadDlg.FileName.Substring(LoadDlg.FileName.Length - 3, 3).ToUpper = "144" Then
                Me.ShowAll = False
                Me.ShowTd3240 = False
                Me.m_type = False
                Me.OpenFile(LoadDlg.FileName)
                Me.m_FileName = LoadDlg.FileName
                Return True
            ElseIf LoadDlg.FileName.Substring(LoadDlg.FileName.Length - 3, 3).ToUpper = "ALL" Then   '小李 地面气象数据All文件导入到数组中
                Me.m_type = True '是否显示144标志
                Me.ShowAll = True '是否显示ALL标志
                Me.ShowTd3240 = False '是否显示TD3240标志
                Me.GeneralMetLoadAll(LoadDlg.FileName)
                Me.m_FileName = LoadDlg.FileName
                Return True
            ElseIf LoadDlg.FileName.Substring(LoadDlg.FileName.Length - 6, 6).ToUpper = "TD3240" Then   '小李 地面气象数据TD3240文件导入到数组中
                Me.m_type = True
                Me.ShowAll = False
                Me.ShowTd3240 = True
                Me.GeneralMetLoadTd3240(LoadDlg.FileName)
                Me.m_FileName = LoadDlg.FileName
                Return True

            Else
                Me.m_FileName = ""
                Me.m_type = True
                Return False
            End If
        Else
            Return False
        End If
    End Function
    ''' <summary>
    ''' 获取路径字符串中 文件的名字
    ''' </summary>
    ''' <param name="sName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetFileName(ByRef sName As String) As String
        Dim nStart As Short
        Dim nEnd As Short
        Dim nLen As Short
        nStart = 1
        nEnd = 1
        nLen = Len(sName)
        While nEnd <> 0
            nEnd = InStr(nStart, sName, "\")
            If nEnd <> 0 Then
                nStart = nEnd + 1
            End If
        End While
        GetFileName = Mid(sName, nStart, nLen - 4 - nStart + 1)
    End Function
    ''' <summary>
    ''' 文件操作
    ''' </summary>
    ''' <param name="file"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function OpenFile(ByVal file As String) As Boolean

        Dim L1 As Integer = 0
        Dim f_year As String = ""
        Dim f_month As String = ""
        Dim f_day As String = ""
        Dim f_hour As String = ""
        Dim a As Integer = 0
        FileOpen(1, file, OpenMode.Input)


        'm_ArrFileCommunication(L) = New FileCommunication
        'm_ArrFileCommunication(L).FarStations.FileName = GetFileName(file)
        'm_ArrFileCommunication(L).FarStations.FilePath = file

        Try
            If file <> "" Then
                Do Until EOF(1)
                    a += 1
                    Dim strline As String = LineInput(1)

                    If a = 1 Then
                        Me.m_Location.SiteId = Mid(strline, 1, 5)

                    End If

                    If strline.Length > 5 Then
                        ReDim Preserve m_ArrayMetData(L1)
                        m_ArrayMetData(L1) = New StructureGeneralMet
                        f_year = Mid(strline, 6, 2)
                        If CInt(f_year) < 10 Then '50年代以前的数据均为2000年  数据年份规定为1950-2050 之间
                            f_year = "200" & CInt(f_year)
                        ElseIf CInt(f_year) <= 50 Then
                            f_year = "20" & CInt(f_year)
                        Else
                            f_year = "19" & CInt(f_year)
                        End If


                        If Mid(strline, 8, 2).StartsWith(" ") = True Then
                            'f_month = "0" & Mid(strline, 9, 1)
                            f_month = " " & Mid(strline, 9, 1)
                        Else
                            f_month = Mid(strline, 8, 2)

                        End If
                        If Mid(strline, 10, 2).StartsWith(" ") = True Then
                            'f_day = "0" & Mid(strline, 11, 1)
                            f_day = " " & Mid(strline, 11, 1)
                        Else
                            f_day = Mid(strline, 10, 2)

                        End If
                        If Mid(strline, 12, 2).StartsWith(" ") = True Then
                            'f_hour = "0" & Mid(strline, 13, 1)
                            f_hour = " " & Mid(strline, 13, 1)
                        Else
                            f_hour = Mid(strline, 12, 2)

                        End If
                        m_ArrayMetData(L1).m_DateTime = New DateTime(CInt(f_year), CInt(f_month), CInt(f_day), CInt(f_hour), 0, 0) '读取时间

                        If Mid(strline, 14, 3).Trim = "" Then
                            'If Mid(strline, 14, 2).Trim = "" Then
                            m_ArrayMetData(L1).m_CloudHeight = 999
                        Else
                            If Mid(strline, 14, 3).Trim = "999" Or Mid(strline, 14, 3).Trim = "---" Or IsNumeric(Mid(strline, 14, 3)) = False Then    '空值按999处理   0按0处理
                                m_ArrayMetData(L1).m_CloudHeight = 999
                            Else
                                'm_ArrayMetData(L1).m_CloudHeight = Mid(strline, 14, 2).Trim
                                m_ArrayMetData(L1).m_CloudHeight = CDbl(Mid(strline, 14, 3).Trim) * 304.8 * 100 / 1000000 * 10   '1英尺=12英寸，1英寸=25.4毫米，25.4*12=304.8毫米   转换成  千米
                            End If
                        End If

                        If Mid(strline, 39, 2).Trim = "" Then
                            m_ArrayMetData(L1).m_Vane = 99
                        Else
                            If Mid(strline, 39, 2).Trim = "99" Then             '空值按   99  处理  '80 为静风  正常数值范围0-36（0-360）
                                m_ArrayMetData(L1).m_Vane = 99
                            Else
                                m_ArrayMetData(L1).m_Vane = CDbl(Mid(strline, 39, 2))
                                m_ArrayMetData(L1).m_Vane = m_ArrayMetData(L1).m_Vane
                            End If

                        End If

                        If Mid(strline, 41, 2).Trim = "" Then
                            m_ArrayMetData(L1).m_WindSpeed = -9999
                        Else
                            If Mid(strline, 41, 2).Trim = "99" Then             '空值按   -9999  处理
                                m_ArrayMetData(L1).m_WindSpeed = -9999
                            Else
                                m_ArrayMetData(L1).m_WindSpeed = CDbl(Mid(strline, 41, 2))
                                m_ArrayMetData(L1).m_WindSpeed = m_ArrayMetData(L1).m_WindSpeed * 18520 / 3600
                            End If

                        End If
                        'm_ArrayMetData(L1).m_Vane = CDbl(Mid(strline, 39, 2))
                        'm_ArrayMetData(L1).m_Vane = m_ArrayMetData(L1).m_Vane * 10  '读入99为空值  读入80 为静风  正常数据00-36
                        'm_ArrayMetData(L1).m_WindSpeed = CInt(Mid(strline, 41, 2))
                        'm_ArrayMetData(L1).m_WindSpeed = m_ArrayMetData(L1).m_WindSpeed * 1.852 / 3.6
                        ' m_ArrayMetData(L1).m_WindSpeed = m_ArrayMetData(L1).m_WindSpeed * 1852*10 / 3600           '1 海里 = 1 852 米 1 海里/小时 = 1852/3600 米/秒
                        If Mid(strline, 43, 4).Trim = "" Then
                            m_ArrayMetData(L1).m_NowPressure = 99999
                        Else
                            If Mid(strline, 43, 4).Trim = "9999" Or Mid(strline, 43, 4).Trim = "" Then
                                m_ArrayMetData(L1).m_NowPressure = 99999
                            Else
                                m_ArrayMetData(L1).m_NowPressure = CInt(Mid(strline, 43, 4).Trim)
                                'm_ArrayMetData(L1).m_NowPressure = CInt(m_ArrayMetData(L1).m_NowPressure * 1013.25 / 2992.126)
                                m_ArrayMetData(L1).m_NowPressure = CInt(m_ArrayMetData(L1).m_NowPressure * 0.01 * 25.4 * 1013.25 * 10 / 760)
                            End If
                        End If

                        If Mid(strline, 47, 3).Trim = "" Then
                            m_ArrayMetData(L1).m_DryTemp = 999
                        Else
                            If Mid(strline, 47, 3).Trim = "999" Then
                                m_ArrayMetData(L1).m_DryTemp = 999
                            Else
                                'm_ArrayMetData(L1).m_DryTemp = CInt(Mid(strline, 47, 3).Trim)
                                'm_ArrayMetData(L1).m_DryTemp = (m_ArrayMetData(L1).m_DryTemp - 32) / 1.8
                                'm_ArrayMetData(L1).m_DryTemp = FormatNumber(m_ArrayMetData(L1).m_DryTemp, 0)
                                m_ArrayMetData(L1).m_DryTemp = ((CInt(Mid(strline, 47, 3).Trim) - 32) * 5 / 9) * 10 '华氏温度转成摄氏度
                                m_ArrayMetData(L1).m_DryTemp = FormatNumber(m_ArrayMetData(L1).m_DryTemp, 0)
                            End If
                        End If

                        'If Mid(strline, 56, 1) = " " Then
                        '    m_ArrayMetData(L1).m_TotalCloud = -1 '有些文件 -1 表示为空值，为保存文件时 区分 "-" 与空值 " "
                        'ElseIf Mid(strline, 56, 1) = "-" Then
                        '    m_ArrayMetData(L1).m_TotalCloud = 10
                        'Else
                        '    m_ArrayMetData(L1).m_TotalCloud = CInt(Mid(strline, 56, 1))
                        'End If

                        If Mid(strline, 56, 1) = " " Then
                            m_ArrayMetData(L1).m_TotalCloud = 0 '空值按 0 处理  0按0处理                    '有些文件 -1 表示为空值，为保存文件时 区分 "-" 与空值 " "
                        ElseIf Mid(strline, 56, 1) = "-" Then
                            m_ArrayMetData(L1).m_TotalCloud = 10
                        Else
                            m_ArrayMetData(L1).m_TotalCloud = CInt(Mid(strline, 56, 1))
                        End If

                        'If Mid(strline, 79, 1) = "-" Then
                        '    m_ArrayMetData(L1).m_LowCloud = 10
                        'ElseIf Mid(strline, 79, 1) = " " Then
                        '    m_ArrayMetData(L1).m_LowCloud = -1 '有些文件 -1 表示低云量为空值，为保存文件时 区分 "-" 与空值 " "
                        'Else
                        '    m_ArrayMetData(L1).m_LowCloud = CInt(Mid(strline, 79, 1))
                        'End If
                        If Mid(strline, 79, 1) = "-" Then
                            m_ArrayMetData(L1).m_LowCloud = 10
                        ElseIf Mid(strline, 79, 1) = " " Then
                            m_ArrayMetData(L1).m_LowCloud = 0 '有些文件 -1 表示低云量为空值，为保存文件时 区分 "-" 与空值 " "
                        Else
                            m_ArrayMetData(L1).m_LowCloud = CInt(Mid(strline, 79, 1))
                        End If
                        If Mid(strline, 53, 3).Trim = "" Then
                            m_ArrayMetData(L1).m_Humidity = 999
                        Else
                            If Mid(strline, 53, 3) = "999" Then     '空值按999处理       0按0处理
                                m_ArrayMetData(L1).m_Humidity = 999
                            Else
                                m_ArrayMetData(L1).m_Humidity = CInt(Mid(strline, 53, 3))
                            End If
                        End If


                        L1 += 1
                    End If



                Loop

            End If
        Catch ex As Exception
            MessageBox.Show("读取数据错误，请检查格式是否正确")
        End Try
        FileClose(1)
    End Function
    Private Sub fil(ByVal t As String)
        Dim a As Char = ""
        'If t.Length > 0 Then
        '    For i As Integer = 0 To t.Length - 1
        '        a = t(i)
        '        If a = (" ") Then
        '            t.Remove(i, 1)

        '        End If
        '    Next

        t.Trim(" ")
        'End If
    End Sub
    ''' <summary>
    ''' 打开数据文件
    ''' </summary>
    ''' <remarks></remarks>
    Public Function LoadSingleAFile(ByVal FileName As String) As MetGeneral
        Dim AMet As New AMet
        AMet.LoadMetData(FileName)
        Dim AMetGeneral As New MetGeneral
        AMetGeneral.ArrayMetData = AMet.ArrayMetData
        AMetGeneral.Location = AMet.Location
        Return AMetGeneral
    End Function
    ''' <summary>
    ''' 从指定文件中导入常规气象数据
    ''' </summary>
    ''' <param name="filename"></param>
    ''' <remarks></remarks>
    Public Sub LoadMetData(ByVal filename As String)
        Me.m_Location = New Location '初始化地理位置参数
        Me.DataType = 0 '初始化数据类型
        Dim LineOfText1 As String = "" '奇数行 。每一组数据由两行组成
        Dim LineOfText2 As String = "" '偶数行
        Dim strLine As String = "" '读取一行
        Try
            FileOpen(1, filename, OpenMode.Input) '打开文件



            Dim startdate As New DateTime '开始时间
            Dim enddate As New DateTime '结束时间

            Dim i As Integer = 0 '用于记数

            Do Until EOF(1)
                strLine = LineInput(1) '读取一行
                If strLine.Contains("LOCATION") Then '如果有地理位置参数
                    m_Location.SiteId = StringHandle.GetString(strLine, 3)

                    If StringHandle.GetString(strLine, 4).EndsWith("E") Then
                        m_Location.Longitude.Number = StringHandle.GetString(strLine, 4).Substring(0, StringHandle.GetString(strLine, 4).Length - 1)
                        m_Location.Longitude.Dir = 0
                    ElseIf StringHandle.GetString(strLine, 4).EndsWith("W") Then
                        m_Location.Longitude.Number = StringHandle.GetString(strLine, 4).Substring(0, StringHandle.GetString(strLine, 4).Length - 1)
                        m_Location.Longitude.Dir = 1
                    ElseIf StringHandle.GetString(strLine, 4).EndsWith("N") Then
                        m_Location.Latitude.Number = StringHandle.GetString(strLine, 4).Substring(0, StringHandle.GetString(strLine, 4).Length - 1)
                        m_Location.Latitude.Dir = 0
                    ElseIf StringHandle.GetString(strLine, 4).EndsWith("S") Then
                        m_Location.Latitude.Number = StringHandle.GetString(strLine, 4).Substring(0, StringHandle.GetString(strLine, 4).Length - 1)
                        m_Location.Latitude.Dir = 1
                    End If

                    If StringHandle.GetString(strLine, 5).EndsWith("N") Then
                        m_Location.Latitude.Number = StringHandle.GetString(strLine, 5).Substring(0, StringHandle.GetString(strLine, 5).Length - 1)
                        m_Location.Latitude.Dir = 0
                    ElseIf StringHandle.GetString(strLine, 5).EndsWith("S") Then
                        m_Location.Latitude.Number = StringHandle.GetString(strLine, 5).Substring(0, StringHandle.GetString(strLine, 5).Length - 1)
                        m_Location.Latitude.Dir = 1
                    ElseIf StringHandle.GetString(strLine, 5).EndsWith("E") Then
                        m_Location.Longitude.Number = StringHandle.GetString(strLine, 5).Substring(0, StringHandle.GetString(strLine, 5).Length - 1)
                        m_Location.Longitude.Dir = 0
                    ElseIf StringHandle.GetString(strLine, 5).EndsWith("W") Then
                        m_Location.Longitude.Number = StringHandle.GetString(strLine, 5).Substring(0, StringHandle.GetString(strLine, 5).Length - 1)
                        m_Location.Longitude.Dir = 1
                    End If
                    m_Location.Tadjust = StringHandle.GetString(strLine, 6)
                End If
                If strLine.Length > 1 Then '读取的奇数行不能为空
                    LineOfText1 = strLine '读取奇数行
                    If InStr(1, LineOfText1, "*") = 0 Then '如果这一行中没有“*”号，则开始记数
                        LineOfText2 = LineInput(1) '读取偶数行 
                        i += 1
                        '由于有2种记录格式：一种是从0点到23点，另一种是从1点到24点。应在这里进行判断
                        Dim IHour As Integer = CInt(Mid(LineOfText1, 8, 2)) '取得小时数
                        If IHour = 24 Then
                            '必选项
                            Me.DataType = 1
                            Exit Do
                        End If
                    End If
                Else
                    Exit Do '跳出
                End If
            Loop
            FileClose(1) '关闭文件

            '按重新设置的时间范围重新设置常规地面气象数据 
            FileOpen(1, filename, OpenMode.Input) '打开文件

            LineOfText1 = "" '奇数行 。每一组数据由两行组成
            LineOfText2 = "" '偶数行
            strLine = "" '读取一行
            i = 0
            Do Until EOF(1)
                strLine = LineInput(1) '读取一行
                If strLine.Length > 1 Then '读取的奇数行不能为空
                    LineOfText1 = strLine '读取奇数行
                    If InStr(1, LineOfText1, "*") = 0 Then '如果这一行中没有“*”号，则开始记数
                        LineOfText2 = LineInput(1) '读取偶数行 
                        i += 1
                        If i = 1 Then '第一个数
                            startdate = GetMetGeneralFromOQA(LineOfText1, LineOfText2).m_DateTime '开始时间
                        End If
                    End If
                Else
                    Exit Do '跳出
                End If
            Loop

            enddate = GetMetGeneralFromOQA(LineOfText1, LineOfText2).m_DateTime '结束时间
            '重新设置时间范围
            Me.ResetArrayMetData(startdate, enddate)
            FileClose(1) '关闭文件

            '按重新设置的时间范围重新设置常规地面气象数据 
            FileOpen(1, filename, OpenMode.Input) '打开文件
            Do Until EOF(1)
                strLine = LineInput(1) '读取一行
                If strLine.Length > 1 Then '读取的奇数行不能为空
                    LineOfText1 = strLine '读取奇数行
                    If InStr(1, LineOfText1, "*") = 0 Then '如果这一行中没有“*”号，则开始记数
                        LineOfText2 = LineInput(1) '读取偶数行 
                        i += 1
                        Me.SetMetData(GetMetGeneralFromOQA(LineOfText1, LineOfText2)) '依次设置数组中的数据
                    End If
                Else
                    Exit Do
                End If
            Loop
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            MessageBox.Show("数据文件出错，请检查数据文件的格式!")
        Finally
            FileClose(1) '关闭文件
        End Try
    End Sub
    ''' <summary>
    ''' 保存地面气象数据文件
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SaveMetData()
        Dim dlgSave As New SaveFileDialog
        dlgSave.Filter = "AERMET 地面气象观测数据文件(*.OQA)|*.OQA"
        If dlgSave.ShowDialog() = DialogResult.OK Then '显示打开对话框
            If dlgSave.FileName <> "" Then
                Me.ExprotsMetData(dlgSave.FileName)
            End If
        End If
    End Sub

    ''' <summary>
    ''' 数组中数据导出到144文件
    ''' </summary>
    ''' <param name="FileName"></param>
    ''' <remarks></remarks>
    Public Sub Exprots144(ByVal FileName As String)



        Dim str As String = ""

        Dim m_year As String = ""
        Dim m_month As String = ""
        Dim m_day As String = ""
        Dim m_hour As String = ""
        Dim m_CloudHeight As String = ""
        Dim m_Vane As String = ""
        Dim m_WindSpeed As String = ""
        'Dim ws As Double
        Dim m_NowPressure As String = ""
        Dim m_TotalCloud As String = ""
        Dim m_LowCloud As String = ""
        Dim m_DryTemp As String = ""
        Dim m_Humidity As String = ""
        Dim swr As StreamWriter
        swr = New StreamWriter(FileName)
        Dim cc As Integer = 0
        For i As Integer = 0 To Me.ArrayMetData.Length - 1

            cc += 1
            If cc = 3 Then
                cc = 0
            End If

            m_year = Mid(Me.ArrayMetData(i).m_DateTime.Year.ToString, 3, 2)
            If Me.ArrayMetData(i).m_DateTime.Month.ToString.Length = 1 Then
                m_month = " " & Me.ArrayMetData(i).m_DateTime.Month.ToString
            Else
                m_month = Me.ArrayMetData(i).m_DateTime.Month.ToString
            End If
            If Me.ArrayMetData(i).m_DateTime.Day.ToString.Length = 1 Then
                m_day = " " & Me.ArrayMetData(i).m_DateTime.Day.ToString
            Else
                m_day = Me.ArrayMetData(i).m_DateTime.Day.ToString
            End If

            If Me.ArrayMetData(i).m_DateTime.Hour.ToString.Length = 1 Then
                m_hour = " " & Me.ArrayMetData(i).m_DateTime.Hour.ToString
            Else
                m_hour = Me.ArrayMetData(i).m_DateTime.Hour.ToString
            End If


            If Me.ArrayMetData(i).m_Vane = 99 Then
                m_Vane = "99"
            Else
                m_Vane = Me.ArrayMetData(i).m_Vane.ToString
                If m_Vane.Length < 2 Then
                    m_Vane = m_Vane.PadLeft(2, " ")
                Else
                    m_Vane = Mid(m_Vane, 1, 2)
                End If
            End If


            'm_Vane = Convert.ToInt32(Me.ArrayMetData(i).m_Vane).ToString()
            'If m_Vane.Length < 2 Then
            '    m_Vane = m_Vane.PadLeft(2, " ")
            'Else
            '    m_Vane = Mid(m_Vane, 1, 2)
            'End If


            If Me.ArrayMetData(i).m_WindSpeed = -9999 Then
                m_WindSpeed = "99"
            Else
                m_WindSpeed = Convert.ToInt32(FormatNumber(Me.ArrayMetData(i).m_WindSpeed * 3.6 / 1.852 / 10, 0)).ToString
                'm_WindSpeed = Me.ArrayMetData(i).m_WindSpeed * 3600 / 18520
                If m_WindSpeed.Length < 2 Then
                    m_WindSpeed = m_WindSpeed.PadLeft(2, " ")
                Else
                    'If Convert.ToDouble(m_WindSpeed) < 10 Then
                    '    ws = Convert.ToDouble(m_WindSpeed)

                    '    ws = FormatNumber(ws, 0)
                    '    If ws = 10 Then
                    '        m_WindSpeed = ws
                    '    Else
                    '        m_WindSpeed = ws
                    '        m_WindSpeed = m_WindSpeed.PadLeft(2, " ")

                    '    End If

                    'Else
                    '    m_WindSpeed = Mid(m_WindSpeed, 1, 2)
                    'End If
                    m_WindSpeed = Mid(m_WindSpeed, 1, 2)
                End If

            End If

            If Me.ArrayMetData(i).m_CloudHeight = 999 Then
                m_CloudHeight = "999"
            Else
                m_CloudHeight = Convert.ToDouble(FormatNumber((Me.ArrayMetData(i).m_CloudHeight * 1000000 / 10 / 304.8 / 100), 0)).ToString
                If m_CloudHeight.Length < 3 Then
                    m_CloudHeight = m_CloudHeight.PadLeft(3, " ")
                Else
                    m_CloudHeight = Mid(m_CloudHeight, 1, 3)
                End If
            End If

            If Me.ArrayMetData(i).m_DryTemp = 999 Then
                m_DryTemp = "999"
            Else
                m_DryTemp = Convert.ToDouble(FormatNumber((((Me.ArrayMetData(i).m_DryTemp / 10) * 9 / 5) + 32), 0)).ToString '摄氏度转成华氏温度

                If m_DryTemp.Length < 3 Then
                    m_DryTemp = m_DryTemp.PadLeft(3, " ")
                Else
                    m_DryTemp = Mid(m_DryTemp, 1, 3)
                End If
            End If

            If Me.ArrayMetData(i).m_NowPressure = 99999 Then
                m_NowPressure = "9999"
            Else
                m_NowPressure = Convert.ToDouble(FormatNumber(Me.ArrayMetData(i).m_NowPressure * 100 * 760 / 25.4 / 1013.25 / 10, 0)).ToString
                If m_NowPressure.Length < 4 Then
                    m_NowPressure = m_NowPressure.PadLeft(4, " ")
                Else
                    m_NowPressure = Mid(m_NowPressure, 1, 4)
                End If
            End If

            If Me.ArrayMetData(i).m_TotalCloud = 99 Or Me.ArrayMetData(i).m_TotalCloud = -1 Then
                m_TotalCloud = "0"
            ElseIf Me.ArrayMetData(i).m_TotalCloud = 10 Then
                m_TotalCloud = "-"
            Else
                m_TotalCloud = Me.ArrayMetData(i).m_TotalCloud.ToString
            End If

            If Me.ArrayMetData(i).m_LowCloud = 10 Then
                m_LowCloud = "-"
            ElseIf Me.ArrayMetData(i).m_LowCloud = -1 Or Me.ArrayMetData(i).m_LowCloud = 99 Then
                m_LowCloud = "0"
            Else
                m_LowCloud = Me.ArrayMetData(i).m_LowCloud.ToString
            End If
            If Me.ArrayMetData(i).m_Humidity = 999 Then
                m_Humidity = "999"
            Else
                m_Humidity = Convert.ToDouble(FormatNumber(m_ArrayMetData(i).m_Humidity, 0)).ToString
                If m_Humidity.Length < 3 Then
                    m_Humidity = m_Humidity.PadLeft(3, " ")
                Else
                    m_Humidity = Mid(m_Humidity, 1, 3)
                End If
            End If



            str = Me.m_Location.SiteId
            str += m_year.ToString & m_month.ToString & m_day.ToString & m_hour.ToString
            str += m_CloudHeight.ToString & "                      " & m_Vane.ToString & m_WindSpeed.ToString
            str += m_NowPressure.ToString & m_DryTemp.ToString & "   " & m_Humidity.ToString
            str += m_TotalCloud.ToString & "                      " & m_LowCloud.ToString ' & vbCrLf
            swr.WriteLine(str)
        Next
        ' swr.WriteLine(str)

        swr.Write(vbCrLf)
        swr.Close()
        swr.Dispose()
    End Sub
    ''' <summary>
    ''' 将数组中的气象数据导到给定的文件中
    ''' </summary>
    ''' <param name="filename">给定的文件名及路径</param>
    ''' <remarks></remarks>
    Public Sub ExprotsMetData(ByVal filename As String)
        Try
            FileOpen(1, filename, OpenMode.Output) '打开文件

            Dim startdate As DateTime = Me.GetStartDate  '开始时间
            Dim enddate As DateTime = Me.GetEndDate  '结束时间
            Dim i As Integer = 0 '用于记数

            '加入头文件的信息
            Dim strAll As String = "*% SURFACE" & vbCrLf
            strAll = strAll & "*@      " & Me.m_Location.OutPutLocation()  '在之前加入地理位置信息
            strAll = strAll & "*** EOH: END OF SURFACE QA HEADERS" & vbCrLf
            For i = 0 To (enddate - startdate).TotalHours
                strAll = strAll & Me.MetToStr(Me.m_ArrayMetData(i)) & vbCrLf
                m_SaveSchedule = (i + 1) / (enddate - startdate).TotalHours
            Next
            If strAll <> "" Then
                '如果不为空，则写入
                PrintLine(1, strAll)
            Else
                MessageBox.Show("地面气象数据为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            FileClose(1) '关闭文件
        End Try
    End Sub
    Public Sub ExprotsOQA(ByVal FileName As String)
        Dim swr As StreamWriter
        swr = New StreamWriter(FileName)
        Dim A As String = ""
        Dim cc As Integer = 0
        Try
            'FileOpen(1, FileName, OpenMode.Output) '打开文件



            '加入头文件的信息
            Dim strAll As String = "*% SURFACE" & vbCrLf
            strAll = strAll & "*@      " & Me.m_Location.OutPutLocation()  '在之前加入地理位置信息
            strAll = strAll & "*** EOH: END OF SURFACE QA HEADERS" ' & vbCrLf
            swr.WriteLine(strAll)
            For i As Integer = 0 To Me.ArrayMetData.Length - 1
                cc = i
                strAll = ""
                strAll = MetToStr(Me.ArrayMetData(i))
                A = strAll
                'swr.WriteLine(strAll)
                swr.Write(strAll)
                swr.Write(vbCrLf)
                ' Exit For
            Next
            'If strAll <> "" Then
            '    '如果不为空，则写入
            '    PrintLine(1, strAll)
            'Else
            'MessageBox.Show("地面气象数据为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
            'End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            swr.Close()
            swr.Dispose() '关闭
        End Try
    End Sub

    ''' <summary>
    ''' 对风向进行插值
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub InsetVane()
        '先设置最前和最后的风速
        Dim IndexFirstVane As Double
        Dim FirstVane As Double = 99
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            If Me.m_ArrayMetData(i).m_Vane <> 99 And Me.m_ArrayMetData(i).m_Vane <> 80 Then '
                IndexFirstVane = i
                FirstVane = Me.m_ArrayMetData(i).m_Vane
                Exit For
            End If
        Next
        'If FirstVane <> 99 Then
        '    For i As Integer = 0 To IndexFirstVane - 1
        '        Me.m_ArrayMetData(i).m_Vane = FirstVane
        '    Next
        'End If
        Dim IndexLastVane As Double
        Dim LastVane As Double = 99
        For i As Integer = Me.m_ArrayMetData.Length - 1 To 0 Step -1
            If Me.m_ArrayMetData(i).m_Vane <> 99 And Me.m_ArrayMetData(i).m_Vane <> 80 Then
                IndexLastVane = i
                LastVane = m_ArrayMetData(i).m_Vane
                Exit For
            End If
        Next
        'If LastVane <> 99 Then
        '    For i As Integer = Me.m_ArrayMetData.Length - 1 To IndexLastVane + 1 Step -1
        '        m_ArrayMetData(i).m_Vane = LastVane
        '    Next
        'End If
        '对中间的风速进行插值
        Dim nStart As Double = IndexFirstVane
        Dim StartVane As Double = FirstVane
        Dim nEnd As Double
        Dim EndVane As Double
        For i As Integer = IndexFirstVane To IndexLastVane
            If m_ArrayMetData(i).m_Vane <> 99 And m_ArrayMetData(i).m_Vane <> 80 Then '在插值时不要对静风进行插值
                nEnd = i
                EndVane = m_ArrayMetData(i).m_Vane
                If nEnd - nStart <= 12 Then '如果两个数之前相关超过12小时，不进行插值
                    If Math.Abs(EndVane - StartVane) > 18 Then '如果为屯角，采取小的角度+360变锐角
                        If EndVane > StartVane Then
                            StartVane = StartVane + 36
                        Else
                            EndVane = EndVane + 36
                        End If
                    End If
                    For j As Integer = nStart + 1 To nEnd - 1
                        If m_ArrayMetData(j).m_Vane <> 80 Then '在插值时不要对静风进行插值
                            m_ArrayMetData(j).m_Vane = StartVane + (j - nStart) * (EndVane - StartVane) / (nEnd - nStart)
                            If m_ArrayMetData(j).m_Vane >= 36 And m_ArrayMetData(j).m_Vane <> 99 Then
                                m_ArrayMetData(j).m_Vane = m_ArrayMetData(j).m_Vane - 36
                            End If
                        End If
                    Next
                End If
                nStart = nEnd
                StartVane = EndVane
            End If
        Next
    End Sub
    ''' <summary>
    ''' 对所有气象进行线性插值
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub InsetAllMetData()
        '风向插值
        InsetVane()

        Dim Adata(Me.m_ArrayMetData.Length - 1) As Integer
        '风速插值
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_WindSpeed
        Next
        LineInset(Adata, -9999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_WindSpeed = Adata(i)
        Next
        m_InsetSchedule = 2 / 24
        ' 总云量，十分制。最小值0，最大值10，默认值99。
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_TotalCloud
        Next
        LineInset(Adata, 99)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_TotalCloud = Adata(i)
        Next
        m_InsetSchedule = 3 / 24
        ' 低云量，十分制。最小值0，最大值10，默认值99。
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_LowCloud
        Next
        LineInset(Adata, 99)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_LowCloud = Adata(i)
        Next
        m_InsetSchedule = 4 / 24
        ' 干球温度，单位摄氏度*10。最小值-300，最大值350。默认值999
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_DryTemp
        Next
        LineInset(Adata, 999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_DryTemp = Adata(i)
        Next
        m_InsetSchedule = 5 / 24
        ' 温球温度，单位摄氏度*10。最小值-650，最大值350。默认值999
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_WetTemp
        Next
        LineInset(Adata, 999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_WetTemp = Adata(i)
        Next
        m_InsetSchedule = 6 / 24
        ' 露点温度，单位摄氏度*10。最小值-650，最大值350。默认值999
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_DewTemp
        Next
        LineInset(Adata, 999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_DewTemp = Adata(i)
        Next

        m_InsetSchedule = 7 / 24
        ' 相对湿度，单位%。最小值0，最大值100，默认值999
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_Humidity
        Next
        LineInset(Adata, 999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_Humidity = Adata(i)
        Next
        m_InsetSchedule = 8 / 24
        ' 降水量，单位mm/h*1000。最小值0，最大值25400，默认值-9。国际单位为mm/h
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_Rainfall
        Next
        LineInset(Adata, -9)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_Rainfall = Adata(i)
        Next
        m_InsetSchedule = 9 / 24
        ' 降水类型。AERMET中无此项
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_RainType
        Next
        LineInset(Adata, 99999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_RainType = Adata(i)
        Next
        m_InsetSchedule = 10 / 24
        ' 海平面气压，millibars*10，即毫巴*1000，最小值为9000，最大值为10999，默认值为99999。国际单位hPa(百帕)。气压为760毫米时相当于1013.25毫巴，这个气压值称为一个标准大气。1毫巴相当于100Pa。
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_SeaPressure
        Next
        LineInset(Adata, 99999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_SeaPressure = Adata(i)
        Next
        m_InsetSchedule = 11 / 24
        ' 观测站地面气压，millibars*10，即毫巴*10，最小值为9000，最大值为10999，默认值为99999。国际单位hPa(百帕)。气压为760毫米时相当于1013.25毫巴，这个气压值称为一个标准大气。1毫巴相当于100Pa。
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_NowPressure
        Next
        LineInset(Adata, 99999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_NowPressure = Adata(i)
        Next
        m_InsetSchedule = 12 / 24
        ' 云底高度，km*10。最大值为300，最小值为0。默认值为999。国际单位为km
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_CloudHeight
        Next
        LineInset(Adata, 999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_CloudHeight = Adata(i)
        Next
        m_InsetSchedule = 13 / 24
        '水平能见度，单位km*10。最大值为1640，最小值为0。默认值为99999。国际单位为km
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_Visibility
        Next
        LineInset(Adata, 99999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_Visibility = Adata(i)
        Next

        m_InsetSchedule = 14 / 24
        ' 1层云层状况，最小值0，最大值300，默认值09999。
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_ALC1
        Next
        LineInset(Adata, 9999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_ALC1 = Adata(i)
        Next
        m_InsetSchedule = 15 / 24

        ' 2层云层状况，最小值0，最大值300，默认值09999。
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_ALC2
        Next
        LineInset(Adata, 9999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_ALC2 = Adata(i)
        Next
        m_InsetSchedule = 16 / 24

        ' 3层云层状况，最小值0，最大值300，默认值09999。
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_ALC3
        Next
        LineInset(Adata, 9999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_ALC3 = Adata(i)
        Next
        m_InsetSchedule = 17 / 24

        ' 4层云层状况，最小值0，最大值300，默认值09999。
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_ALC4
        Next
        LineInset(Adata, 9999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_ALC4 = Adata(i)
        Next
        m_InsetSchedule = 18 / 24
        ' 5层云层状况，最小值0，最大值300，默认值09999。
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_ALC5
        Next
        LineInset(Adata, 9999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_ALC5 = Adata(i)
        Next
        m_InsetSchedule = 19 / 24
        ' 6层云层状况，最小值0，最大值300，默认值09999。
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_ALC6
        Next
        LineInset(Adata, 9999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_ALC6 = Adata(i)
        Next
        m_InsetSchedule = 20 / 24
        ' 天气代码(临近地)，最小值9292，最大值98300，默认值9999
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_PWVC
        Next
        LineInset(Adata, 9999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_PWVC = Adata(i)
        Next
        m_InsetSchedule = 21 / 24

        ' 天气代码，最小值9292，最大值98300，默认值9999
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_PWTH
        Next
        LineInset(Adata, 9999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_PWTH = Adata(i)
        Next
        m_InsetSchedule = 22 / 24

        ' ASOS天气，十分制，最小值0，最大值10，默认值99
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_ASKY
        Next
        LineInset(Adata, 99)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_ASKY = Adata(i)
        Next
        m_InsetSchedule = 23 / 24
        ' ASOS高度，最小值0，最大值888，默认值999
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Adata(i) = Me.m_ArrayMetData(i).m_ACHT
        Next
        LineInset(Adata, 999)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            Me.m_ArrayMetData(i).m_ACHT = Adata(i)
        Next
        m_InsetSchedule = 24 / 24

    End Sub

    ''' <summary>
    '''  线性插值
    ''' </summary>
    ''' <param name="Adata">需要插值的数组</param>
    ''' <param name="defaultData">缺失数据代码</param>
    ''' <remarks></remarks>
    Public Sub LineInset(ByVal Adata() As Integer, ByVal defaultData As Integer)
        '先设置最前和最后的风速
        Dim IndexFirstdata As Integer
        Dim Firstdata As Integer = defaultData
        For i As Integer = 0 To Adata.Length - 1
            If Adata(i) <> defaultData Then '
                IndexFirstdata = i
                Firstdata = Adata(i)
                Exit For
            End If
        Next
        'If Firstdata <> defaultData Then
        '    For i As Integer = 0 To IndexFirstdata - 1
        '        Adata(i) = Firstdata
        '    Next
        'End If
        Dim IndexLastdata As Integer
        Dim Lastdata As Integer = defaultData
        For i As Integer = Adata.Length - 1 To 0 Step -1
            If Adata(i) <> defaultData Then
                IndexLastdata = i
                Lastdata = Adata(i)
                Exit For
            End If
        Next
        'If Lastdata <> defaultData Then
        '    For i As Integer = Adata.Length - 1 To IndexLastdata + 1 Step -1
        '        Adata(i) = Lastdata
        '    Next
        'End If
        '对中间的风速进行插值
        Dim nStart As Integer = IndexFirstdata
        Dim Startdata As Integer = Firstdata
        Dim nEnd As Integer
        Dim Enddata As Integer
        For i As Integer = IndexFirstdata To IndexLastdata
            If Adata(i) <> defaultData Then
                nEnd = i
                Enddata = Adata(i)
                If nEnd - nStart <= 12 Then '如果两个数之前相关超过12小时，不进行插值
                    For j As Integer = nStart + 1 To nEnd - 1
                        Adata(j) = Startdata + (j - nStart) * (Enddata - Startdata) / (nEnd - nStart)
                    Next
                End If

                nStart = nEnd
                Startdata = Enddata
            End If
        Next
    End Sub
    ''' <summary>
    ''' 将从文件中获取的字符串转成常规气象数据
    ''' </summary>
    ''' <param name="str1"></param>
    ''' <param name="str2"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetMetGeneralFromOQA(ByVal str1 As String, ByVal str2 As String) As StructureGeneralMet   '从OQA文件的一行中记取时间数据
        Dim MetGen As New StructureGeneralMet
        Dim strYear As String = Mid(str1, 2, 2)
        If CInt(strYear) < 10 Then '50年代以前的数据均为2000年
            strYear = "200" & CInt(strYear)
        ElseIf CInt(strYear) <= 50 Then
            strYear = "20" & CInt(strYear)
        Else
            strYear = "19" & CInt(strYear)
        End If
        '由于有aermet2种记录格式：一种是从0点到23点，另一种是从1点到24点。应在这里进行判断。如果用24小时表示，则应表示为第2天的0点。
        If Me.DataType = 1 Then
            '必选项
            MetGen.m_DateTime = New DateTime(CInt(strYear), CInt(Mid(str1, 4, 2)), CInt(Mid(str1, 6, 2)), CInt(Mid(str1, 8, 2)) - 1, 0, 0) '读取时间,并减1小时
        Else
            '必选项
            MetGen.m_DateTime = New DateTime(CInt(strYear), CInt(Mid(str1, 4, 2)), CInt(Mid(str1, 6, 2)), CInt(Mid(str1, 8, 2)), 0, 0) '读取时间
        End If
        '必选项
        '风向
        If CInt(Mid(str2, 73, 2)) = 0 Then 'OQA文件用0表示静风。我的内部结构用80表示静风
            MetGen.m_Vane = 80
        Else
            MetGen.m_Vane = CInt(Mid(str2, 73, 2)) '风向
        End If
        MetGen.m_WindSpeed = CInt(Mid(str2, 76, 5)) '风速
        MetGen.m_TotalCloud = CInt(Mid(str1, 36, 2)) '总云量
        MetGen.m_LowCloud = CInt(Mid(str1, 38, 2)) '低云量
        MetGen.m_DryTemp = CInt(Mid(str2, 46, 5)) '干球温度
        '可选项
        MetGen.m_WetTemp = CInt(Mid(str2, 52, 5)) '湿球温度
        MetGen.m_DewTemp = CInt(Mid(str2, 58, 5)) '露点温度
        MetGen.m_Humidity = CInt(Mid(str2, 64, 5)) '相对湿度
        MetGen.m_Rainfall = CInt(Mid(str1, 11, 5)) '降水量
        MetGen.m_SeaPressure = CInt(Mid(str1, 17, 5)) '海平面气压
        MetGen.m_NowPressure = CInt(Mid(str1, 23, 5)) '观测点地面气压
        MetGen.m_CloudHeight = CInt(Mid(str1, 31, 3)) '云底高度
        MetGen.m_Visibility = CInt(Mid(str2, 40, 5)) '水平能见度
        '其它项
        MetGen.m_ALC1 = CInt(Mid(str1, 41, 5)) '1层云层状况
        MetGen.m_ALC2 = CInt(Mid(str1, 47, 5)) '2层云层状况
        MetGen.m_ALC3 = CInt(Mid(str1, 53, 5)) '3层云层状况
        MetGen.m_ALC4 = CInt(Mid(str1, 59, 5)) '4层云层状况
        MetGen.m_ALC5 = CInt(Mid(str1, 65, 5)) '5层云层状况
        MetGen.m_ALC6 = CInt(Mid(str2, 10, 5)) '6层云层状况
        MetGen.m_PWVC = CInt(Mid(str2, 16, 5)) '天气代码(临近地)
        MetGen.m_PWTH = CInt(Mid(str2, 22, 5)) '天气代码
        MetGen.m_ASKY = CInt(Mid(str2, 28, 5)) 'ASOS天气
        MetGen.m_ACHT = CInt(Mid(str2, 34, 5)) 'ASOS高度

        Return MetGen
    End Function
    Private Function CharIndex(ByVal str As String) As String
        Dim strIndex As Integer = -1
        strIndex = str.IndexOf(".")
        If strIndex <> -1 Then
            str = str.Remove(strIndex, str.Length - strIndex)
        Else
            str = str
        End If
        Return str
    End Function
    
    ''' <summary>
    ''' 将一个地面气象数据转换为字符串
    ''' </summary>
    ''' <param name="MetGen"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function MetToStr(ByVal MetGen As StructureGeneralMet) As String
        Dim str1 As String = ""
        Dim str2 As String = ""
        Dim strVane As String = ""

        'If Me.Type = True Then
        '    If CInt(MetGen.m_Vane) = 0 Then '在aermet中用0表示静风，用36表示N风向。
        '        strVane = "36"
        '    ElseIf MetGen.m_Vane = 80 Then
        '        strVane = "0"
        '    Else
        '        strVane = CharIndex(MetGen.m_Vane) ' CInt(MetGen.m_Vane)
        '    End If
        '    str1 = str1 & " " & MetGen.m_DateTime.Year.ToString.Substring(2, 2) & MetGen.m_DateTime.Month.ToString.PadLeft(2, "0") & MetGen.m_DateTime.Day.ToString.PadLeft(2, "0") & MetGen.m_DateTime.Hour.ToString.PadLeft(2, "0") _
        '           & MetGen.m_Rainfall.ToString.PadLeft(6) _
        '           & " " & MetGen.m_SeaPressure.ToString.PadLeft(5) _
        '           & " " & MetGen.m_NowPressure.ToString.PadLeft(5) _
        '           & " " & MetGen.m_CloudHeight.ToString.PadLeft(5) _
        '           & " 0" & MetGen.m_TotalCloud.ToString.PadLeft(2, "0") _
        '           & MetGen.m_LowCloud.ToString.PadLeft(2, "0") _
        '           & " " & MetGen.m_ALC1.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_ALC2.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_ALC3.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_ALC4.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_ALC5.ToString.PadLeft(5, "0")
        '    strVane = Mid(strVane, 1, 2)
        '    str2 = "".PadLeft(9) & MetGen.m_ALC6.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_PWVC.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_PWTH.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_ASKY.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_ACHT.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_Visibility.ToString.PadLeft(5) _
        '           & " " & MetGen.m_DryTemp.ToString.PadLeft(5) _
        '           & " " & MetGen.m_WetTemp.ToString.PadLeft(5) _
        '           & " " & MetGen.m_DewTemp.ToString.PadLeft(5) _
        '           & " " & MetGen.m_Humidity.ToString.PadLeft(5) _
        '           & " " & strVane.ToString.PadLeft(5) _
        '           & " " & MetGen.m_WindSpeed.ToString.PadLeft(5)
        'Else
        '    If CInt(MetGen.m_Vane) = 0 Then '在aermet中用0表示静风，用36表示N风向。
        '        strVane = "36"
        '    ElseIf MetGen.m_Vane = 8 Then
        '        strVane = "0"
        '    Else
        '        strVane = CharIndex(MetGen.m_Vane) * 10 ' CInt(MetGen.m_Vane)
        '    End If
        '    str1 = str1 & " " & MetGen.m_DateTime.Year.ToString.Substring(2, 2) & MetGen.m_DateTime.Month.ToString.PadLeft(2, "0") & MetGen.m_DateTime.Day.ToString.PadLeft(2, "0") & MetGen.m_DateTime.Hour.ToString.PadLeft(2, "0") _
        '           & MetGen.m_Rainfall.ToString.PadLeft(6) _
        '           & " " & MetGen.m_SeaPressure.ToString.PadLeft(5) _
        '           & " " & MetGen.m_NowPressure.ToString.PadLeft(5) _
        '           & " " & MetGen.m_CloudHeight.ToString.PadLeft(5) _
        '           & " 0" & MetGen.m_TotalCloud.ToString.PadLeft(2, "0") _
        '           & MetGen.m_LowCloud.ToString.PadLeft(2, "0") _
        '           & " " & MetGen.m_ALC1.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_ALC2.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_ALC3.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_ALC4.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_ALC5.ToString.PadLeft(5, "0")
        '    strVane = Mid(strVane, 1, 2)
        '    str2 = "".PadLeft(9) & MetGen.m_ALC6.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_PWVC.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_PWTH.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_ASKY.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_ACHT.ToString.PadLeft(5, "0") _
        '           & " " & MetGen.m_Visibility.ToString.PadLeft(5) _
        '           & " " & MetGen.m_DryTemp.ToString.PadLeft(5) _
        '           & " " & MetGen.m_WetTemp.ToString.PadLeft(5) _
        '           & " " & MetGen.m_DewTemp.ToString.PadLeft(5) _
        '           & " " & MetGen.m_Humidity.ToString.PadLeft(5) _
        '           & " " & strVane.ToString.PadLeft(5) _
        '           & " " & MetGen.m_WindSpeed.ToString.PadLeft(5)
        'End If
        If CInt(MetGen.m_Vane) = 0 Then '在aermet中用0表示静风，用36表示N风向。
            strVane = "36"
        ElseIf MetGen.m_Vane = 80 Then
            strVane = "0"
        Else
            strVane = CharIndex(MetGen.m_Vane) ' CInt(MetGen.m_Vane)
        End If
        str1 = str1 & " " & MetGen.m_DateTime.Year.ToString.Substring(2, 2) & MetGen.m_DateTime.Month.ToString.PadLeft(2, "0") & MetGen.m_DateTime.Day.ToString.PadLeft(2, "0") & MetGen.m_DateTime.Hour.ToString.PadLeft(2, "0") _
               & MetGen.m_Rainfall.ToString.PadLeft(6) _
               & " " & MetGen.m_SeaPressure.ToString.PadLeft(5) _
               & " " & MetGen.m_NowPressure.ToString.PadLeft(5) _
               & " " & MetGen.m_CloudHeight.ToString.PadLeft(5) _
               & " 0" & MetGen.m_TotalCloud.ToString.PadLeft(2, "0") _
               & MetGen.m_LowCloud.ToString.PadLeft(2, "0") _
               & " " & MetGen.m_ALC1.ToString.PadLeft(5, "0") _
               & " " & MetGen.m_ALC2.ToString.PadLeft(5, "0") _
               & " " & MetGen.m_ALC3.ToString.PadLeft(5, "0") _
               & " " & MetGen.m_ALC4.ToString.PadLeft(5, "0") _
               & " " & MetGen.m_ALC5.ToString.PadLeft(5, "0")
        strVane = Mid(strVane, 1, 2)
        str2 = "".PadLeft(9) & MetGen.m_ALC6.ToString.PadLeft(5, "0") _
               & " " & MetGen.m_PWVC.ToString.PadLeft(5, "0") _
               & " " & MetGen.m_PWTH.ToString.PadLeft(5, "0") _
               & " " & MetGen.m_ASKY.ToString.PadLeft(5, "0") _
               & " " & MetGen.m_ACHT.ToString.PadLeft(5, "0") _
               & " " & MetGen.m_Visibility.ToString.PadLeft(5) _
               & " " & MetGen.m_DryTemp.ToString.PadLeft(5) _
               & " " & MetGen.m_WetTemp.ToString.PadLeft(5) _
               & " " & MetGen.m_DewTemp.ToString.PadLeft(5) _
               & " " & MetGen.m_Humidity.ToString.PadLeft(5) _
               & " " & strVane.ToString.PadLeft(5) _
               & " " & MetGen.m_WindSpeed.ToString.PadLeft(5)

        Return str1 & vbCrLf & str2

    End Function
    Public Function DirectToAngle(ByVal strDirect As String) As Double
        strDirect = strDirect.Trim.ToUpper
        Select Case strDirect.ToUpper
            Case "N"
                Return 22.5 * 0 / 10
            Case "NNE"
                Return 22.5 * 1 / 10
            Case "NE"
                Return 22.5 * 2 / 10
            Case "ENE"
                Return 22.5 * 3 / 10

            Case "E"
                Return 22.5 * 4 / 10

            Case "ESE"
                Return 22.5 * 5 / 10

            Case "SE"
                Return 22.5 * 6 / 10
            Case "SSE"
                Return 22.5 * 7 / 10
            Case "S"
                Return 22.5 * 8 / 10
            Case "SSW"
                Return 22.5 * 9 / 10
            Case "SW"
                Return 22.5 * 10 / 10
            Case "WSW"
                Return 22.5 * 11 / 10
            Case "W"
                Return 22.5 * 12 / 10
            Case "WNW"
                Return 22.5 * 13 / 10
            Case "NW"
                Return 22.5 * 14 / 10
            Case "NNW"
                Return 22.5 * 15 / 10
            Case Else
                Return 99
        End Select
    End Function

    Public Function Clone() As Object Implements System.ICloneable.Clone
        Dim objCopy As New MetGeneral()
        objCopy.m_DataChanged = Me.m_DataChanged
        ReDim objCopy.m_ArrayMetData(Me.m_ArrayMetData.Length - 1)
        For i As Integer = 0 To Me.m_ArrayMetData.Length - 1
            objCopy.m_ArrayMetData(i) = Me.m_ArrayMetData(i).Clone
        Next
        objCopy.m_FileName = Me.m_FileName
        objCopy.DataType = Me.DataType
        objCopy.m_Location = Me.m_Location.Clone
        objCopy.m_InsetSchedule = Me.m_InsetSchedule '输出选项类
        objCopy.m_SaveSchedule = Me.m_SaveSchedule
        objCopy.m_IsInsert = Me.m_IsInsert
        Return objCopy
    End Function
    '小李
    '地面导出All文件
    '数据从数组导出到文件
    Public Sub GeneralMetExprotsAll(ByVal FileName As String)

        '站点号 值00000到-99999 空值处理 无
        Dim m_LocationNum As String = ""
        Dim m_ASKY As String = "" 'ASOS标志 值blankor A  A表示数据来源ASOS站点  空值处理 空格

        '年        '月        '日        '时   空值处理 无
        Dim m_DateTime As DateTime = Now
        Dim m_Year As String = ""
        Dim m_Month As String = ""
        Dim m_Day As String = ""
        Dim m_Hour As String = ""

        'GRAD  值0000 - 1415    空值处理9999
        Dim Grad As String = "9999"
        'DRAD  值0000 - 1415    空值处理9999
        Dim Drad As String = "9999"


        Dim m_TotalCloud As String = "99" '总云量  值00 - 10      空值处理99
        Dim m_LowCloud As String = "99" '低云量  值00 - 10      空值处理99
        Dim m_DryTemp As String = "999.9" '干球温度  值-70.0 - 60.0   空值处理999.9

        '内插标志   值 空格或者I  空值处理 空格
        Dim m_InsertSign As String = " "


        Dim m_DewTemp As String = "999.9" '漏点温度 值-70.0 60.0  空值处理 999.9

        Dim m_Humidity As String = "9999" '相对湿度   值000 - 100 百分数  空值处理 9999

        Dim m_SeaPressure As String = "9999" '站点气压  值0700 -1100  百帕 空值处理 9999

        '内插标志


        Dim m_Vane As String = "999" '风向  值000 - 360 度 空值处理  999

        Dim m_WindSpeed As String = "99.9" '风速  M/s   空值处理 99.9

        Dim m_Visibility As String = "999.9" '能见度 0 - 777.7 千米  空值处理 999.9

        Dim m_CloudHeight As String = "99999" '云底高度  00000 - 88888  米 空值处理  99999

        '现时天气  天气条件  00009999
        Dim m_PWTH As String = "00009999"

        'ASOS CLOUD LAYER 1  空值处理 99999
        'ASOS CLOUD LAYER 2   空值处理 99999
        'ASOS CLOUD LAYER 3   空值处理 99999

        Dim AsosCloudLayer1 As String = "99999"
        Dim AsosCloudLayer2 As String = "99999"
        Dim AsosCloudLayer3 As String = "99999"
        '小时降雨量   值  0 - 999  空值处理  0
        Dim m_Rainfall As String = "0"


        Dim m_RainType As String = " " '降雨标志  值 空格 A、 D、 M   空值处理  空格

        Dim m_SnowDeepth As String = "0" '雪深  值 000 - 100  英寸 空值处理 999

        Dim Str As String
        'Dim ws As Double
        Dim swr As StreamWriter
        swr = New StreamWriter(FileName)
        Dim cc As Integer = 0

        For i As Integer = -1 To Me.ArrayMetData.Length - 1

            If (i = -1) Then
                Str = "  1     " + "2        " + "3    " + "4    " + "5 " + "6    " + "7      " + "8    " + "9  " + "10    " + "11  " + "12     " + "13    " + "14      " + "15     " + "16    " + "17    " + "18     " + "19   " + "20" '& vbCrLf
                swr.WriteLine(Str)
            Else

                cc += 1
                If cc = 3 Then
                    cc = 0
                End If

                'ReDim Preserve m_ArrayMetData(i)
                'm_ArrayMetData(i) = New StructureGeneralMet

                m_LocationNum = Me.Location.SiteId                                '站台编号
                m_ASKY = " "

                m_Year = Mid(Me.ArrayMetData(i).m_DateTime.Year.ToString, 1, 4)            '年

                If Me.ArrayMetData(i).m_DateTime.Month.ToString.Length = 1 Then
                    m_Month = " " & Me.ArrayMetData(i).m_DateTime.Month.ToString         '月
                Else
                    m_Month = Me.ArrayMetData(i).m_DateTime.Month.ToString
                End If
                If Me.ArrayMetData(i).m_DateTime.Day.ToString.Length = 1 Then            '日
                    m_Day = " " & Me.ArrayMetData(i).m_DateTime.Day.ToString
                Else
                    m_Day = Me.ArrayMetData(i).m_DateTime.Day.ToString
                End If

                If Me.ArrayMetData(i).m_DateTime.Hour.ToString.Length = 1 Then            '时
                    If Me.ArrayMetData(i).m_DateTime.Hour = 9 Then
                        m_Hour = ((Me.ArrayMetData(i).m_DateTime.Hour) + 1).ToString
                    Else
                        m_Hour = " " & ((Me.ArrayMetData(i).m_DateTime.Hour) + 1).ToString
                    End If
                Else
                    m_Hour = ((Me.ArrayMetData(i).m_DateTime.Hour) + 1).ToString
                End If

                Grad = "9999"
                Drad = "9999"
                'If Me.ArrayMetData(i).m_TotalCloud Is Null Then
                If Trim(Me.ArrayMetData(i).m_TotalCloud.ToString) Is Nothing Then                '总云量
                    m_TotalCloud = "99"
                Else
                    m_TotalCloud = Convert.ToDouble(FormatNumber(Me.ArrayMetData(i).m_TotalCloud, 0)).ToString
                    If m_TotalCloud.Length < 2 Then
                        m_TotalCloud = m_TotalCloud.PadLeft(2, "0")
                    Else
                        m_TotalCloud = Mid(m_TotalCloud, 1, 2)
                    End If

                End If

                If Trim(Me.ArrayMetData(i).m_TotalCloud.ToString) Is Nothing Then                  ' 低云量
                    m_LowCloud = "99"
                Else
                    m_LowCloud = Convert.ToDouble(FormatNumber(Me.ArrayMetData(i).m_LowCloud, 0)).ToString
                    If m_LowCloud.Length < 2 Then
                        m_LowCloud = m_LowCloud.PadLeft(2, "0")
                    Else
                        m_LowCloud = Mid(m_LowCloud, 1, 2)
                    End If
                End If

                If Trim(Me.ArrayMetData(i).m_DryTemp.ToString) Is Nothing Then                '干球温度
                    m_DryTemp = "999.9"
                Else
                    If Me.ArrayMetData(i).m_DryTemp = 999 Then
                        m_DryTemp = "999.9"
                    Else
                        If Me.ArrayMetData(i).m_DryTemp < 0 Then
                            ' m_DryTemp = (Me.ArrayMetData(i).m_DryTemp / 10 * 70 / 30).ToString
                            m_DryTemp = (Me.ArrayMetData(i).m_DryTemp / 10).ToString
                            If m_DryTemp.Length < 5 Then
                                m_DryTemp = m_DryTemp.PadLeft(5, " ")
                            ElseIf m_DryTemp.Length = 5 Then
                                m_DryTemp = Mid(m_DryTemp, 1, 5)
                            ElseIf Mid(m_DryTemp, 5, 1) = "." Then
                                m_DryTemp = " " + Mid(m_DryTemp, 1, 4)
                            Else
                                m_DryTemp = Mid(m_DryTemp, 1, 5)
                            End If
                        Else
                            'm_DryTemp = (Me.ArrayMetData(i).m_DryTemp / 10 * 60 / 35).ToString
                            m_DryTemp = (Me.ArrayMetData(i).m_DryTemp / 10).ToString
                            If m_DryTemp.Length < 5 Then
                                m_DryTemp = m_DryTemp.PadLeft(5, " ")
                            ElseIf m_DryTemp.Length = 5 Then
                                m_DryTemp = Mid(m_DryTemp, 1, 5)
                            ElseIf Mid(m_DryTemp, 5, 1) = "." Then
                                m_DryTemp = " " + Mid(m_DryTemp, 1, 4)
                            Else
                                m_DryTemp = Mid(m_DryTemp, 1, 5)
                            End If
                        End If


                    End If

                End If

                m_InsertSign = " "                                               '内插标志

                If Trim((Me.ArrayMetData(i).m_DewTemp) / 10).ToString Is Nothing Then                  ' 漏点温度
                    m_DewTemp = "999.9"
                Else
                    If ((Me.ArrayMetData(i).m_DewTemp)) = 999 Then
                        m_DewTemp = "999.9"
                    Else
                        If Me.ArrayMetData(i).m_DewTemp < 0 Then
                            'm_DewTemp = ((Me.ArrayMetData(i).m_DewTemp) / 10 * 70 / 65).ToString
                            m_DewTemp = ((Me.ArrayMetData(i).m_DewTemp) / 10).ToString
                            If m_DewTemp.Length < 5 Then
                                m_DewTemp = m_DewTemp.PadLeft(5, " ")
                            ElseIf m_DewTemp.Length = 5 Then
                                m_DewTemp = Mid(m_DewTemp, 1, 5)
                            ElseIf Mid(m_DewTemp, 5, 1) = "." Then
                                m_DewTemp = " " + Mid(m_DewTemp, 1, 4)
                            Else
                                m_DewTemp = Mid(m_DewTemp, 1, 5)
                            End If
                        Else
                            'm_DewTemp = ((Me.ArrayMetData(i).m_DewTemp) / 10 * 60 / 35).ToString
                            m_DewTemp = ((Me.ArrayMetData(i).m_DewTemp) / 10).ToString
                            If m_DewTemp.Length < 5 Then
                                m_DewTemp = m_DewTemp.PadLeft(5, " ")
                            ElseIf m_DewTemp.Length = 5 Then
                                m_DewTemp = Mid(m_DewTemp, 1, 5)
                            ElseIf Mid(m_DewTemp, 5, 1) = "." Then
                                m_DewTemp = " " + Mid(m_DewTemp, 1, 4)
                            Else
                                m_DewTemp = Mid(m_DewTemp, 1, 5)
                            End If
                        End If


                    End If
                End If

                If Trim(((Me.ArrayMetData(i).m_Humidity)).ToString) Is Nothing Then                  ' 相对湿度
                    m_Humidity = "999"
                Else
                    If ((Me.ArrayMetData(i).m_Humidity)) = 999 Then
                        m_Humidity = "999"
                    Else
                        m_Humidity = Convert.ToDouble(FormatNumber(Me.ArrayMetData(i).m_Humidity, 0)).ToString
                        If m_Humidity.Length < 3 Then
                            m_Humidity = m_Humidity.PadLeft(3, "0")
                        Else
                            m_Humidity = Mid(m_Humidity, 1, 3)
                        End If
                    End If
                End If

                If Trim(Me.ArrayMetData(i).m_NowPressure.ToString) Is Nothing Then          '站点气压
                    m_SeaPressure = "9999"
                Else
                    If Me.ArrayMetData(i).m_NowPressure = 99999 Then
                        m_SeaPressure = "9999"
                    Else
                        'm_SeaPressure = ((Me.ArrayMetData(i).m_NowPressure) / 10 * 1800 / 19.999).ToString
                        'm_SeaPressure = (((Me.ArrayMetData(i).m_NowPressure) / 10 - 900) / 199.9 * 400 + 700).ToString
                        m_SeaPressure = Convert.ToDouble(FormatNumber(((Me.ArrayMetData(i).m_NowPressure) / 10), 0)).ToString
                        If m_SeaPressure.Length < 4 Then
                            m_SeaPressure = m_SeaPressure.PadLeft(4, " ")
                        Else
                            m_SeaPressure = Mid(m_SeaPressure, 1, 4)
                        End If
                    End If
                End If

                If Trim(((Me.ArrayMetData(i).m_Vane) / 10).ToString) Is Nothing Then
                    m_Vane = "999"
                Else
                    If ((Me.ArrayMetData(i).m_Vane)) = 99 Then
                        m_Vane = "999"
                    End If
                    If ((Me.ArrayMetData(i).m_Vane)) = 80 Then
                        m_Vane = "000"
                    End If
                    If ((Me.ArrayMetData(i).m_Vane)) <> 99 And ((Me.ArrayMetData(i).m_Vane)) <> 80 Then
                        m_Vane = Convert.ToDouble(FormatNumber(((Me.ArrayMetData(i).m_Vane) * 10), 0)).ToString()            '风向
                        ' m_Vane = ((Me.ArrayMetData(i).m_Vane) /10).ToString()            '风向
                    End If
                End If

                If m_Vane.Length < 3 Then
                    m_Vane = m_Vane.PadLeft(3, " ")
                Else
                    m_Vane = Mid(m_Vane, 1, 3)
                End If


                If Trim(Me.ArrayMetData(i).m_WindSpeed.ToString) Is Nothing Then                     '风速
                    m_WindSpeed = "99.9"
                Else
                    If Me.ArrayMetData(i).m_WindSpeed = -9999 Then
                        m_WindSpeed = "99.9"
                    Else
                        m_WindSpeed = ((Me.ArrayMetData(i).m_WindSpeed) / 10).ToString
                    End If
                End If


                If m_WindSpeed.Length = 1 Then

                    m_WindSpeed = m_WindSpeed.PadLeft(2, " ") + ".0"

                ElseIf m_WindSpeed.Length < 4 Then

                    m_WindSpeed = m_WindSpeed.PadLeft(4, " ")
                ElseIf m_WindSpeed.Length = 4 Then
                    m_WindSpeed = Mid(m_WindSpeed, 1, 4)
                ElseIf Mid(m_WindSpeed, 4, 1) = "." Then
                    m_WindSpeed = " " + Mid(m_WindSpeed, 1, 4)
                Else
                    m_WindSpeed = Mid(m_WindSpeed, 1, 4)
                End If

                    If Trim(((Me.ArrayMetData(i).m_Visibility) / 10).ToString) Is Nothing Then                  ' 能见度
                        m_Visibility = "999.9"
                    Else
                        ' If ((Me.ArrayMetData(i).m_Visibility) / 10) = 99999 Then
                        If ((Me.ArrayMetData(i).m_Visibility)) = 99999 Then
                            m_Visibility = "999.9"
                        Else
                            'm_Visibility = ((Me.ArrayMetData(i).m_Visibility) / 10 * 777.7 / 164).ToString
                            m_Visibility = ((Me.ArrayMetData(i).m_Visibility) / 10).ToString
                            If m_Visibility.Length < 5 Then
                                m_Visibility = m_Visibility.PadLeft(5, " ")
                            ElseIf m_Visibility.Length = 5 Then
                                m_Visibility = Mid(m_Visibility, 1, 5)
                            ElseIf Mid(m_Visibility, 5, 1) = "." Then
                                m_Visibility = " " + Mid(m_Visibility, 1, 4)
                            Else
                                m_Visibility = Mid(m_Visibility, 1, 5)
                            End If
                        End If
                    End If

                    If Me.ArrayMetData(i).m_LowCloud = 0 Then
                        m_CloudHeight = "77777"
                    Else
                        If Trim(((Me.ArrayMetData(i).m_CloudHeight)).ToString) Is Nothing Then
                            'If Trim(((m_CloudHeight2(i)) * 100).ToString) Is Nothing Then                     ' 云底高度  新文件 米  国际标准 表格 km
                            'If Trim(((Me.ArrayMetData(i).m_CloudHeight2) * 100).ToString) Is Nothing Then                     ' 云底高度  新文件 米  国际标准 表格 km
                            m_CloudHeight = "77777"
                        Else
                            'If (m_CloudHeight2(i)) = 999 Then
                            If (Me.ArrayMetData(i).m_CloudHeight) = 999 Then
                                m_CloudHeight = "77777"
                            Else

                                m_CloudHeight = Convert.ToDouble(FormatNumber(((Me.ArrayMetData(i).m_CloudHeight) * 100), 0)).ToString
                                ' m_CloudHeight = ((Me.ArrayMetData(i).m_CloudHeight2) * 100 * 88.888 / 30).ToString
                                'm_CloudHeight = ((Me.ArrayMetData(i).m_CloudHeight) * 10).ToString
                                If m_CloudHeight.Length < 5 Then
                                    m_CloudHeight = m_CloudHeight.PadLeft(5, " ")
                                Else
                                    m_CloudHeight = Mid(m_CloudHeight, 1, 5)
                                End If
                            End If
                        End If
                    End If


                    'If Trim(((Me.ArrayMetData(i).m_CloudHeight)).ToString) Is Nothing Then
                    '    'If Trim(((m_CloudHeight2(i)) * 100).ToString) Is Nothing Then                     ' 云底高度  新文件 米  国际标准 表格 km
                    '    'If Trim(((Me.ArrayMetData(i).m_CloudHeight2) * 100).ToString) Is Nothing Then                     ' 云底高度  新文件 米  国际标准 表格 km
                    '    m_CloudHeight = "99999"
                    'Else
                    '    'If (m_CloudHeight2(i)) = 999 Then
                    '    If (Me.ArrayMetData(i).m_CloudHeight) = 999 Then
                    '        m_CloudHeight = "99999"
                    '    Else

                    '        m_CloudHeight = ((Me.ArrayMetData(i).m_CloudHeight) * 100).ToString
                    '        ' m_CloudHeight = ((Me.ArrayMetData(i).m_CloudHeight2) * 100 * 88.888 / 30).ToString
                    '        'm_CloudHeight = ((Me.ArrayMetData(i).m_CloudHeight) * 10).ToString
                    '        If m_CloudHeight.Length < 5 Then
                    '            m_CloudHeight = m_CloudHeight.PadLeft(5, " ")
                    '        Else
                    '            m_CloudHeight = Mid(m_CloudHeight, 1, 5)
                    '        End If
                    '    End If
                    'End If

                    'If (((Me.ArrayMetData(i).m_PWVC)).ToString) Is Nothing Then                  ' 现时天气
                    m_PWTH = "00009999"
                    '    Else
                    '    m_PWTH = ((Me.ArrayMetData(i).m_PWVC)).ToString
                    '    If m_PWTH.Length < 8 Then
                    '        m_PWTH = m_PWTH.PadLeft(8, "0")
                    '    Else
                    '        m_PWTH = Mid(m_PWTH, 1, 8)
                    '    End If
                    'End If

                    If (((Me.ArrayMetData(i).m_Rainfall)).ToString) Is Nothing Then             ' 小时降雨量
                        m_Rainfall = "  0"
                    Else
                        If ((Me.ArrayMetData(i).m_Rainfall)) = -9 Then
                            m_Rainfall = "  0"
                        Else
                            ' m_Rainfall = ((Me.ArrayMetData(i).m_Rainfall) / 1000 * 999 / 25.4).ToString
                            m_Rainfall = Convert.ToDouble(FormatNumber(((Me.ArrayMetData(i).m_Rainfall) / 1000 / 25.4 / 100), 0)).ToString '1英寸=25.4毫米
                            If m_Rainfall.Length < 3 Then
                                m_Rainfall = m_Rainfall.PadLeft(3, " ")
                            Else
                                m_Rainfall = Mid(m_Rainfall, 1, 3)
                            End If
                        End If


                    End If

                    'm_Rainfall = " "                                                 '降雨标志
                    m_SnowDeepth = "  0"                                              '雪深



                    Str = Me.m_Location.SiteId + m_ASKY + m_Year.ToString & m_Month.ToString & m_Day.ToString & m_Hour.ToString
                    Str += " " + Grad + " " + Drad + " " + m_TotalCloud + m_LowCloud + " " + m_DryTemp + "  " + m_DewTemp + " " + m_Humidity + " " + m_SeaPressure + "  " + m_Vane + " " + m_WindSpeed + "  " + m_Visibility + " " + m_CloudHeight + " " + m_PWTH + " " + "99999" + " " + "99999" + " " + "99999" + "  " + m_Rainfall + "  " + m_SnowDeepth '& vbCrLf
                    swr.WriteLine(Str)
            End If
        Next


        'swr.Write(vbCrLf)
        swr.Close()
        swr.Dispose()

    End Sub
    '小李
    '地面导入TD3240文件
    '将数据从数组导出到文件

    Public Sub GeneralMetExprotsTD3240(ByVal m_SaveFileName As String)

        Dim m_LocationNum As String = ""
        Dim m_DateTime As DateTime = Now '年        '月        '日        '时   空值处理 无
        Dim m_Year As String = ""
        Dim m_Month As String = ""
        Dim m_Day As String = ""
        Dim m_Hour As String = ""
        Dim m_Rainfall As String = ""  '空值为99999

        Dim Str As String
        Dim swr As StreamWriter
        swr = New StreamWriter(m_SaveFileName)
        Dim cc As Integer = 0

        For i As Integer = 0 To Me.ArrayMetData.Length - 1



            'ReDim Preserve m_ArrayMetData(i)
            'm_ArrayMetData(i) = New StructureGeneralMet

            'm_LocationNum = Me.Location.SiteId                                '站台编号



            If Me.Location.SiteId.Length = 5 Then
                m_LocationNum = Me.Location.SiteId + "000"                               '站台编号
            ElseIf Me.Location.SiteId.Length < 5 Then
                m_LocationNum = Me.Location.SiteId.PadRight(5, "0") + "000"                               '站台编号
            Else
                m_LocationNum = Me.Location.SiteId.Substring(0, 5) + "000"
            End If




            m_Year = Mid(Me.ArrayMetData(i).m_DateTime.Year.ToString, 1, 4)            '年

            If Me.ArrayMetData(i).m_DateTime.Month.ToString.Length = 1 Then
                m_Month = "0" & Me.ArrayMetData(i).m_DateTime.Month.ToString         '月
            Else
                m_Month = Me.ArrayMetData(i).m_DateTime.Month.ToString
            End If
            If Me.ArrayMetData(i).m_DateTime.Day.ToString.Length = 1 Then            '日
                m_Day = "000" & Me.ArrayMetData(i).m_DateTime.Day.ToString
            Else
                m_Day = "00" & Me.ArrayMetData(i).m_DateTime.Day.ToString
            End If

            If Me.ArrayMetData(i).m_DateTime.Hour.ToString.Length = 1 Then            '时
                If Me.ArrayMetData(i).m_DateTime.Hour = 9 Then
                    m_Hour = ((Me.ArrayMetData(i).m_DateTime.Hour) + 1).ToString + "00"
                Else
                    m_Hour = "0" & ((Me.ArrayMetData(i).m_DateTime.Hour) + 1).ToString + "00"
                End If
            Else
                m_Hour = ((Me.ArrayMetData(i).m_DateTime.Hour) + 1).ToString + "00"
            End If



            If (((Me.ArrayMetData(i).m_Rainfall)).ToString) Is Nothing Then             ' 小时降雨量
                m_Rainfall = "00000"
            Else
                If ((Me.ArrayMetData(i).m_Rainfall)) = -9 Then
                    m_Rainfall = "00000"
                Else
                    ' m_Rainfall = ((Me.ArrayMetData(i).m_Rainfall) / 1000 * 999 / 25.4).ToString
                    m_Rainfall = Convert.ToDouble(FormatNumber(((Me.ArrayMetData(i).m_Rainfall) * 100 / 1000 / 25.4), 0)).ToString '1英寸=25.4毫米
                    If m_Rainfall.Length < 5 Then
                        m_Rainfall = m_Rainfall.PadLeft(5, "0")
                    Else
                        m_Rainfall = Mid(m_Rainfall, 1, 5)
                    End If
                End If
            End If




            Str = "HPD" + m_LocationNum + "HPCPHI" + m_Year.ToString & m_Month.ToString & m_Day.ToString + "001" & m_Hour.ToString + "0" + m_Rainfall
            swr.WriteLine(Str)
            ' ''HPD54715000HPCPHI20060100010100000000
        Next

        'swr.Write(vbCrLf)
        swr.Close()
        swr.Dispose()
    End Sub

    '小李
    '地面导入All文件

    'Public AllFileFormat As Integer = 0 '标记显示时间格式0-23（=0时）还是1-24（=1时）
    Public ShowAll As Boolean = False   '在表格中显示All文件的标志
    'Public m_CloudHeight2() As Double '= {999}

    '小李
    '地面导入All文件
    '文件数据导入数组
    Public Sub GeneralMetLoadAll(ByVal file As String)

        ShowAll = True


        Dim m_LocationNum As String = "" '站点号 值00000到-99999 空值处理 无
        Dim m_ASKY As String = "" 'ASOS标志 值blankor A  A表示数据来源ASOS站点  空值处理 空格
        Dim m_DateTime As DateTime = Now '年        '月        '日        '时   空值处理 无
        Dim m_Year As String = ""
        Dim m_Month As String = ""
        Dim m_Day As String = ""
        Dim m_Hour As String = ""
        Dim Grad As String = "9999" 'GRAD  值0000 - 1415    空值处理9999
        Dim Drad As String = "9999" 'DRAD  值0000 - 1415    空值处理9999
        Dim m_TotalCloud As String = "99" '总云量  值00 - 10      空值处理99
        Dim m_LowCloud As String = "99" '低云量  值00 - 10      空值处理99
        Dim m_InsertSign As String = " " '内插标志   值 空格或者I  空值处理 空格
        Dim m_DewTemp As String = "999.9" '漏点温度 值-70.0 60.0  空值处理 999.9
        Dim m_Humidity As String = "9999" '相对湿度   值000 - 100 百分数  空值处理 9999
        Dim m_SeaPressure As String = "9999" '站点气压  值0700 -1100  百帕 空值处理 9999
        'Dim m_NowPressure As Double = 99999  '观测站地面气压
        Dim m_NowPressure As String = "9999"  '观测站地面气压
        '内插标志
        Dim m_Vane As String = "999" '风向  值000 - 360 度 空值处理  999
        Dim m_WindSpeed As String = "99.9" '风速  M/s   空值处理 99.9
        Dim m_Visibility As String = "999.9" '能见度 0 - 777.7 千米  空值处理 999.9
        Dim m_CloudHeight As String = "99999" '云底高度  00000 - 88888  米 空值处理  99999
        Dim m_PWTH As String = "00009999" '现时天气  天气条件  00009999
        'ASOS CLOUD LAYER 1  空值处理 99999
        'ASOS CLOUD LAYER 2   空值处理 99999
        'ASOS CLOUD LAYER 3   空值处理 99999
        Dim AsosCloudLayer1 As String = "99999"
        Dim AsosCloudLayer2 As String = "99999"
        Dim AsosCloudLayer3 As String = "99999"
        Dim m_Rainfall As String = "0" '小时降雨量   值  0 - 999  空值处理  0
        Dim m_RainType As String = " " '降雨标志  值 空格 A、 D、 M   空值处理  空格
        Dim m_SnowDeepth As String = "0" '雪深  值 000 - 100  英寸 空值处理 999
        'Dim L1 As Integer = 0
        Dim L1 As Integer = -1
        Dim f_year As String = ""
        Dim f_month As String = ""
        Dim f_day As String = ""
        Dim f_hour As String = ""
        Dim a As Integer = 0
        Dim m_WetTemp As Double = 999  '湿球温度
        'Me.DataType = 1 '时间格式为1-24 若 Me .DataType =0则时间格式为0-23 默认为0
        'Dim AllFileFormat As Integer = 0 '标记显示时间格式0-23（=0时）还是1-24（=1时）

        FileOpen(1, file, OpenMode.Input)

        Dim TimeStyle As Boolean = False  '标记显示时间格式0-23（false时）还是1-24（true时）
        Dim str As String
        str = LineInput(1)
        For Num As Integer = 0 To 26
            str = LineInput(1)
            'ReDim Preserve m_ArrayMetData(Num)
            'm_ArrayMetData(Num) = New StructureGeneralMet

            f_hour = Convert.ToInt32(Trim(Mid(str, 15, 2)))
            If f_hour = 24 Then
                TimeStyle = True
                Exit For
            Else
                TimeStyle = False
            End If
        Next

        FileClose(1)

        FileOpen(1, file, OpenMode.Input)

        Try
            If file <> "" Then

                Do Until EOF(1)
                    Dim strline As String = LineInput(1)

                    If L1 > -1 Then

                        ReDim Preserve m_ArrayMetData(L1)
                        m_ArrayMetData(L1) = New StructureGeneralMet

                        ''''''''''''''''''''''
                        'ReDim Preserve m_CloudHeight2(L1)
                        '''''''''''''''''''''

                        Me.m_Location.SiteId = GetString(strline, 1)

                        f_year = Trim(Mid(strline, 7, 4))
                        f_month = Trim(Mid(strline, 11, 2))
                        f_day = Trim(Mid(strline, 13, 2))

                        'If CInt(f_day) = 24 Then
                        '    AllFileFormat = 1 '显示时间格式为1-24
                        'Else
                        '    AllFileFormat = 0 '显示时间格式为0-23
                        'End If
                        'If L1 = 0 AndAlso CInt(f_day) = 0 Then
                        '    f_hour = Convert.ToInt32(Trim(Mid(strline, 15, 2))) '文件是以0-23时间格式记录
                        'Else
                        '    f_hour = Convert.ToInt32(Trim(Mid(strline, 15, 2))) - 1 '文件是以1-24时间格式记录
                        'End If
                        If TimeStyle = False Then
                            f_hour = Convert.ToInt32(Trim(Mid(strline, 15, 2))) '文件是以0-23时间格式记录
                        Else
                            f_hour = Convert.ToInt32(Trim(Mid(strline, 15, 2))) - 1 '文件是以1-24时间格式记录
                        End If


                        Dim mDataTime As String = f_month & "/" & f_day & "/" & f_year & " " & f_hour & ":00:00"
                        m_ArrayMetData(L1).m_DateTime = mDataTime
                        'm_ArrayMetData(L1).m_DateTime = New DateTime(CInt(f_year), CInt(f_month), CInt(f_day), CInt(f_hour), 0, 0) '读取时间

                        If CDbl(GetString(strline, GetStringNumber(strline) - 9)) = 999 Then
                            m_ArrayMetData(L1).m_Vane = 99
                        Else
                            'm_ArrayMetData(L1).m_Vane = CDbl(GetString(strline, GetStringNumber(strline) - 9)) * 10 '风向
                            m_ArrayMetData(L1).m_Vane = CDbl(GetString(strline, GetStringNumber(strline) - 9)) * 0.1 '风向
                        End If


                        If CDbl(GetString(strline, GetStringNumber(strline) - 8)) = 99.9 Then
                            m_ArrayMetData(L1).m_WindSpeed = -9999
                        Else
                            ' m_ArrayMetData(L1).m_WindSpeed = CDbl(GetString(strline, GetStringNumber(strline) - 8)) * 0.1 '风速
                            m_ArrayMetData(L1).m_WindSpeed = CDbl(GetString(strline, GetStringNumber(strline) - 8)) * 10 '风速
                        End If


                        'm_ArrayMetData(L1).m_TotalCloud = CDbl(GetString(strline, GetStringNumber(strline) - 14)) '总云量低云量
                        Dim aa As String = (GetString(strline, GetStringNumber(strline) - 14)) '总云量低云量
                        If CDbl(Mid(aa, 1, 2)) = 99 Then
                            m_ArrayMetData(L1).m_TotalCloud = 99
                        Else
                            m_ArrayMetData(L1).m_TotalCloud = CDbl(Mid(aa, 1, 2)) '总云量
                        End If

                        If CDbl(Mid(aa, 3, 2)) = 99 Then
                            m_ArrayMetData(L1).m_LowCloud = 99
                        Else
                            m_ArrayMetData(L1).m_LowCloud = CDbl(Mid(aa, 3, 2)) '低云量
                        End If
                        If CDbl(GetString(strline, GetStringNumber(strline) - 13)) = 999.9 Then
                            m_ArrayMetData(L1).m_DryTemp = 999
                        Else
                            If CDbl(GetString(strline, GetStringNumber(strline) - 13)) < 0 Then
                                m_ArrayMetData(L1).m_DryTemp = CDbl(GetString(strline, GetStringNumber(strline) - 13)) * 10    '0.1 '干球温度
                                'm_ArrayMetData(L1).m_DryTemp = CDbl(GetString(strline, GetStringNumber(strline) - 13)) * 10 * 30 / 70
                            Else
                                m_ArrayMetData(L1).m_DryTemp = CDbl(GetString(strline, GetStringNumber(strline) - 13)) * 10    '0.1 '干球温度
                                'm_ArrayMetData(L1).m_DryTemp = CDbl(GetString(strline, GetStringNumber(strline) - 13)) * 10 * 35 / 60 '干球温度
                            End If
                        End If



                        '''''''可选项
                        'm_ArrayMetData(L1)''''''''''''''''湿球温度
                        If CDbl(GetString(strline, GetStringNumber(strline) - 12)) = 999.9 Then
                            m_ArrayMetData(L1).m_DewTemp = 999
                        Else
                            If CDbl(GetString(strline, GetStringNumber(strline) - 12)) < 0 Then
                                m_ArrayMetData(L1).m_DewTemp = CDbl(GetString(strline, GetStringNumber(strline) - 12)) * 10    '0.1 '漏点温度
                                'm_ArrayMetData(L1).m_DewTemp = CDbl(GetString(strline, GetStringNumber(strline) - 12)) * 10 * 65 / 70
                            Else
                                m_ArrayMetData(L1).m_DewTemp = CDbl(GetString(strline, GetStringNumber(strline) - 12)) * 10    ' 0.1 '漏点温度
                                'm_ArrayMetData(L1).m_DewTemp = CDbl(GetString(strline, GetStringNumber(strline) - 12)) * 10 * 35 / 60 '漏点温度

                            End If

                        End If
                        If CDbl(GetString(strline, GetStringNumber(strline) - 11)) = 999 Then
                            m_ArrayMetData(L1).m_Humidity = 999
                        Else
                            m_ArrayMetData(L1).m_Humidity = CDbl(GetString(strline, GetStringNumber(strline) - 11)) '相对湿度
                        End If
                        If CDbl(GetString(strline, GetStringNumber(strline) - 1)) = 0 Then
                            m_ArrayMetData(L1).m_Rainfall = -9
                        Else
                            ' m_ArrayMetData(L1).m_Rainfall = CDbl(GetString(strline, GetStringNumber(strline) - 1)) * 0.0001 '降雨量
                            m_ArrayMetData(L1).m_Rainfall = CDbl(GetString(strline, GetStringNumber(strline) - 1)) * 25.4 * 100 * 1000  '降雨量  1 英寸=25.4毫米
                            'm_ArrayMetData(L1).m_Rainfall = CDbl(GetString(strline, GetStringNumber(strline) - 1)) * 1000 * 25.4 / 999 '降雨量
                        End If
                        If CDbl(GetString(strline, GetStringNumber(strline) - 10)) = 9999 Then
                            m_ArrayMetData(L1).m_NowPressure = 99999
                        Else
                            'm_ArrayMetData(L1).m_SeaPressure = CDbl(GetString(strline, GetStringNumber(strline) - 10)) * 0.1 '观测点地面气压
                            m_ArrayMetData(L1).m_NowPressure = CDbl(GetString(strline, GetStringNumber(strline) - 10)) * 10  '观测点地面气压
                            'm_ArrayMetData(L1).m_SeaPressure = (CDbl(GetString(strline, GetStringNumber(strline) - 10)) * 10 - 7000) / 4000 * 1999 + 9000  ' * 19.999 / 1800 '海平面气压
                        End If

                       
                        'If CDbl(GetString(strline, GetStringNumber(strline) - 6)) = 99999 Then
                        If CDbl(GetString(strline, GetStringNumber(strline) - 6)) = 77777 Then
                            m_ArrayMetData(L1).m_CloudHeight = 999

                        Else
                            'm_ArrayMetData(L1).m_CloudHeight = CDbl(GetString(strline, GetStringNumber(strline) - 6)) * 100 '云底高度
                            'm_ArrayMetData(L1).m_CloudHeight2 = CDbl(GetString(strline, GetStringNumber(strline) - 6)) * 0.01 * 30 / 88.888 '云底高度

                            m_ArrayMetData(L1).m_CloudHeight = FormatNumber(CDbl(GetString(strline, GetStringNumber(strline) - 6)) * 0.01, 1)  '云底高度
                        End If
                        'End If

                        'If CDbl(GetString(strline, GetStringNumber(strline) - 6)) = 99999 Then
                        '    ' m_ArrayMetData(L1).m_CloudHeight2 = 999
                        '    m_CloudHeight2(L1) = 999
                        'Else
                        '    'm_ArrayMetData(L1).m_CloudHeight = CDbl(GetString(strline, GetStringNumber(strline) - 6)) * 100 '云底高度
                        '    'm_ArrayMetData(L1).m_CloudHeight2 = CDbl(GetString(strline, GetStringNumber(strline) - 6)) * 0.01 * 30 / 88.888 '云底高度

                        '    'm_ArrayMetData(L1).m_CloudHeight2 = CDbl(GetString(strline, GetStringNumber(strline) - 6)) * 0.01 '云底高度
                        '    m_CloudHeight2(L1) = CDbl(GetString(strline, GetStringNumber(strline) - 6)) * 0.01 '云底高度
                        'End If
                        If CDbl(GetString(strline, GetStringNumber(strline) - 7)) = 999.9 Then
                            m_ArrayMetData(L1).m_Visibility = 99999
                        Else
                            ' m_ArrayMetData(L1).m_Visibility = CDbl(GetString(strline, GetStringNumber(strline) - 7)) * 0.1 '能见度
                            m_ArrayMetData(L1).m_Visibility = CDbl(GetString(strline, GetStringNumber(strline) - 7)) * 10  '能见度
                            'm_ArrayMetData(L1).m_Visibility = CDbl(GetString(strline, GetStringNumber(strline) - 7)) * 10 * 164 / 777.7 '能见度
                        End If

                        'If (GetString(strline, GetStringNumber(strline) - 5)) = "00009999" Then
                        m_ArrayMetData(L1).m_PWVC = 9999
                        'Else
                        '    m_ArrayMetData(L1).m_PWVC = CDbl(GetString(strline, GetStringNumber(strline) - 5))  '现时天气
                        'End If

                        m_ArrayMetData(L1).m_WetTemp = 999 '湿球温度
                        m_ArrayMetData(L1).m_SeaPressure = 99999 '海平面气压

                    End If

                    L1 += 1

                    'End If
                Loop

            End If
        Catch ex As Exception
            '  L -= 1
        End Try
        FileClose(1)
    End Sub

    '小李
    '导入td3240到数组
    Public ShowTd3240 As Boolean = False
    ' 导入td3240到数组 
    Public Sub GeneralMetLoadTd3240(ByVal file As String)

        Dim m_LocationNum As String = "" '站点号 值00000到-99999 空值处理 无
        Dim m_DateTime As DateTime = Now      '年        '月        '日        '时   空值处理 无
        Dim m_Year As String = ""
        Dim m_Month As String = ""
        Dim m_Day As String = ""
        Dim m_Hour As String = ""
        Dim m_Rainfall As String = "0" '小时降雨量   值  0 - 999  空值处理  0
        Dim TimeStyle As Boolean = False  '标记显示时间格式0-23（false时）还是1-24（true时）
        FileOpen(1, file, OpenMode.Input)
        Dim str As String
        Dim L1 As Integer = 0
        For Num As Integer = 0 To 26
            str = LineInput(1)
            'ReDim Preserve m_ArrayMetData(Num)
            'm_ArrayMetData(Num) = New StructureGeneralMet

            m_Hour = Convert.ToInt32(Trim(Mid(str, 31, 2)))
            If m_Hour = 24 Then
                TimeStyle = True
                Exit For
            Else
                TimeStyle = False
            End If
        Next
        FileClose(1)
        FileOpen(1, file, OpenMode.Input)

        Try
            If file <> "" Then
                Do Until EOF(1)
                    str = LineInput(1)

                    ReDim Preserve m_ArrayMetData(L1)
                    m_ArrayMetData(L1) = New StructureGeneralMet

                    'Me.m_Location.SiteId = Trim(Mid(str, 4, 8))
                    Me.m_Location.SiteId = Trim(Mid(str, 4, 5))
                    m_Year = Trim(Mid(str, 18, 4))
                    m_Month = Trim(Mid(str, 22, 2))
                    m_Day = Trim(Mid(str, 26, 2))


                    If TimeStyle = False Then
                        m_Hour = Convert.ToInt32(Trim(Mid(str, 31, 2))) '文件是以0-23时间格式记录
                    Else
                        m_Hour = Convert.ToInt32(Trim(Mid(str, 31, 2))) - 1 '文件是以1-24时间格式记录
                    End If


                    Dim mDataTime As String = m_Month & "/" & m_Day & "/" & m_Year & " " & m_Hour & ":00:00"
                    m_ArrayMetData(L1).m_DateTime = mDataTime

                    If CDbl(Trim(Mid(str, 36, 5))) = 99999 Then
                        m_ArrayMetData(L1).m_Rainfall = -9
                    Else
                        m_ArrayMetData(L1).m_Rainfall = CDbl(Trim(Mid(str, 36, 5))) * 25.4 * 0.01 * 1000  '降雨量  1 英寸=25.4毫米
                    End If

                    L1 = L1 + 1
                Loop
            End If
        Catch ex As Exception

        End Try

        FileClose(1)

    End Sub

End Class
